1 MsgBox Val(Workbooks(1).Worksheets(1).Range("b:b").Find("*", , , , , xlPrevious).Row)'查找最大行號 2 3 MsgBox Val(Workbooks(1).Worksheets(1).Range("b:b").Find("*", , , , , xlPrevious).column)'查找最大列號
存在數據的最大行列號:
Sub 查找數據單元格的最大行列號()
MsgBox "數據單元格的最大行號: " & Cells.Find("*", , , , 1, 2).Row
MsgBox "數據單元格的最大列號: " & Cells.Find("*", , , , 2, 2).Column
End Sub
For循環例子
Sub 選擇文件提取文件名() Dim i% Dim arr() Dim reg As New RegExp With reg .Global = True .Pattern = "[^\\]+(?=\.xls.?$)" End With arr = Application.GetOpenFilename("文件類型 (*.xls;),*.xls;", , "選擇文件", , True) For i = LBound(arr) To UBound(arr) Set mh = reg.Execute(arr(i)) Cells(i, 1).Value = mh(0) Next End Sub