我已经创建了一个AddIn,需要引用A列中的最后一个单元格。我一直在常规宏中执行此操作,但在AddIn中有时间。
我试过
lRow2 = ThisWorkbook.Sheets("Client").Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count
和
lRow2 = ThisWorkbook.Sheets(1).Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count
甚至
Dim ws2 As Worksheet
Dim lRow2 As Long
Set ws2 = ThisWorkbook.Sheets("Client")
With ws2
lRow2 = .Range("A" & .Rows.Count).End(xlUp).Row
End With
仅返回值1的值不正确。
我已经读过我必须使用ThisWorkbook
来引用AddIn工作表,但我要么下标超出范围,要么对象不支持这种方法我试图写这个方法的各种方式进行。
答案 0 :(得分:0)
我很亲密。这将检索addin工作表的正确的最后一行编号
With Workbooks("Book1.xlam").Sheets("Sheet1")
lRow = Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count
End With