Question

I'm trying to calculate the number of used rows in a VBA project in Excel 2013 so that I can fill it with a userform (everytime I press the Save button, it adds a new row to the worksheet). The worksheet also has two header rows, so I don't want them to be overwritten.

This should be accomplished by the following code that gets executed as soon as I press the Save button:

Private Sub Save_Click()

Dim totalRows As Long

totalRows = Daten.Cells(Rows.Count, "A").End(xlUp).Row
If totalRows < 2 Then
totalRows = 2
Else
totalRows = totalRows
End If

...

End Sub

However, when I press the Save button, I get the Error "424" Object Required".

I am really lost here - anyone knows what I'm doing wrong? If you need to know more, please tell me so, because I'd really want to see this work.

Was it helpful?

Solution

This seems to do the trick (as suggested in the comments)

Dim totalRows As Long

totalRows = Sheets("Daten").Cells(Rows.Count, "A").End(xlUp).Row
If totalRows < 2 Then
totalRows = 2
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top