简体   繁体   English

AddIn工作表的最后一行

[英]Last row of AddIn worksheet

I've created an AddIn and need to reference the last cell in column A. I do this all the time in regular macros but having a time with it in the AddIn. 我已经创建了一个AddIn,并且需要引用A列中的最后一个单元格。我一直在常规宏中执行此操作,但是在AddIn中有一段时间。

I've tried 我试过了

lRow2 = ThisWorkbook.Sheets("Client").Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count

and

lRow2 = ThisWorkbook.Sheets(1).Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Count

even 甚至

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

which only returns a value of 1 which is not correct. 仅返回不正确的值1。

I've read that I have to use ThisWorkbook to refer to the AddIn worksheet but I either get subscript out of range or object doesn't support this methods in the various way I've tried to write this out. 我读过我必须使用ThisWorkbook来引用AddIn工作表,但是我要么下标超出范围,要么对象不支持我尝试写出的各种方式的此方法。

I was close. 我离得很近。 This retrieves the correct last row number for the addin worksheet 这将为外接程序工作表检索正确的最后一行号

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

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

End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM