加载项工作表的最后一行



我创建了一个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工作表,但我要么得到了超出范围的下标,要么对象不支持我尝试过的各种方法。

我很接近。这将检索加载项工作表的正确最后一行编号

With Workbooks("Book1.xlam").Sheets("Sheet1")
lRow = Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count
End With

最新更新