[英]Get last used Row and Column in an Excel Sheet without opening it
Can I get the last used row number and column number for a Worksheet without opening it or using Interop (which is very slow)? 是否可以在不打开工作表或不使用Interop的情况下(非常慢)获取工作表的最后使用的行号和列号?
Thanks 谢谢
Without opening the sheet or the workbook in it's entirety? 没有完全打开工作表或工作簿? As Mike asked, what platform are you trying to do this in?
正如Mike所问,您正在尝试在哪个平台上执行此操作?
If you are trying to do it within the workbook you could create a module (open VBA with ALT+11), Insert, Module. 如果要在工作簿中执行此操作,则可以创建一个模块(使用ALT + 11打开VBA),插入,模块。
Sub lastusedcell()
Dim lastcol As Long
Dim lastrow As Long
lastcol = Worksheets("Sheet2").Cells.Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column
lastrow = Worksheets("Sheet2").Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
MsgBox "Last used cell is (colnumber:rownumber) " & lastcol & ":" & lastrow
End Sub
Change "Sheet2" to the appropriate sheet name. 将“ Sheet2”更改为适当的工作表名称。 If you want to check for cells with formulas too, replace
如果您还要检查带有公式的单元格,请替换
LookIn:=xlValues with LookIn:=xlFormulas
Answer source Source website with a few modifications for answer 答案来源来源网站对答案做了一些修改
Then run the macro manually of create a button to do it or call the function if you need the values in VBA. 然后,手动运行宏以创建一个按钮来执行此操作;如果需要VBA中的值,则调用该函数。
The closest I have found to this in the smartsheet documentation are the following keyboard shortcuts. 我在智能表文档中找到的与此最接近的是以下键盘快捷键。 It appears that [Ctrl] + [Up Arrow} and [Ctrl] + [Left Arrow} are equivalent to [Ctrl] + [Home], and [Ctrl] + [Down Arrow} and [Ctrl] + [Right Arrow} are equivalent as [Ctrl] + [End].
看来[Ctrl] + [上箭头]和[Ctrl] + [左箭头]等效于[Ctrl] + [Home],而[Ctrl] + [下箭头]和[Ctrl] + [右箭头]分别是等同于[Ctrl] + [End]。 I have not figured out an equivalent for the row navigation [Home] and [End] keyboard shortcuts.
我还没有找到等效的行导航[Home]和[End]键盘快捷键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.