我得到了一个 Run-time error '424': Object Required
错误,代码如下。
Sub GetData()
ThisWorkbook.Worksheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1).Row.Value = ActiveWorkbook.Name
ThisWorkbook.Worksheets(1).Range("B" & Rows.Count).End(xlUp).Offset(1).Row.Value = ActiveWorkbook.Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row
End Sub
摆脱 .Row
- 这将返回行号,而不是单元格的引用。
Sub GetData()
With ThisWorkbook.Worksheets(1)
.Range("A" & Rows.Count).End(xlUp).Offset(1).Value2 = ActiveWorkbook.Name
.Range("B" & Rows.Count).End(xlUp).Offset(1).Value2 = ActiveWorkbook.Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row
End With
End Sub