尝试计算使用的行数时,错误424“Object Required”

我试图计算在Excel 2013 VBA项目中使用的行数,以便我可以用一个用户窗体填充它(每次我按保存button,它将添加一个新的行到工作表)。 工作表也有两个标题行,所以我不希望他们被覆盖。

这应该通过下面的代码来完成,只要按下Savebutton就会执行:

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 

但是,当我按保存button,我得到错误“424”对象要求“。

我真的迷失在这里 – 任何人都知道我在做什么错了? 如果你需要了解更多,请告诉我,因为我真的想看到这个工作。

这似乎是伎俩(正如评论中所build议的那样)

 Dim totalRows As Long totalRows = Sheets("Daten").Cells(Rows.Count, "A").End(xlUp).Row If totalRows < 2 Then totalRows = 2 End If