Excel VBA-使用数据查找最后一列 [英] Excel VBA- Finding the last column with data
本文介绍了Excel VBA-使用数据查找最后一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现这种方法可以在表格中找到包含行的最后一个数据:
I've found this method for finding the last data containing row in a sheet:
ws.Range("A65536").End(xlUp).row
是否有类似的方法来查找包含列的最后一个数据在一张表中?
Is there a similar method for finding the last data containing column in a sheet?
谢谢。
推荐答案
做这个。最可靠的是找到。
Lots of ways to do this. The most reliable is find.
Dim rLastCell As Range
Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
MsgBox ("The last used column is: " & rLastCell.Column)
如果你想找到您可以使用的特定行中使用的最后一列:
If you want to find the last column used in a particular row you can use:
Dim lColumn As Long
lColumn = ws.Cells(1, Columns.Count).End(xlToLeft).Column
范围(不太可靠):
Dim lColumn As Long
lColumn = ws.UsedRange.Columns.Count
如果列A中没有数据,使用使用范围将无法使用。有关另一个问题,请参阅使用范围:
Using used range wont work if you have no data in column A. See here for another issue with used range:
请参阅这里关于重置使用范围。
See Here regarding resetting used range.
这篇关于Excel VBA-使用数据查找最后一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文