AddIn工作表的最后一行

时间:2016-04-27 22:05:21

标签: excel vba excel-vba

我已经创建了一个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工作表,但我要么下标超出范围,要么对象不支持这种方法我试图写这个方法的各种方式进行。

1 个答案:

答案 0 :(得分:0)

我很亲密。这将检索addin工作表的正确的最后一行编号

With Workbooks("Book1.xlam").Sheets("Sheet1")

lRow = Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count

End With
相关问题