运行时错误'424'。当使用ThisWorkbook时出现 "需要对象 "错误

问题描述 投票:0回答:1

我得到了一个 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
excel vba excel-vba
1个回答
1
投票

摆脱 .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
© www.soinside.com 2019 - 2024. All rights reserved.