在VBA里如何获取当前工作表里数据的行数和列数

如题,谢谢!
2024-11-08 06:40:17
推荐回答(2个)
回答1:

iRows=activesheet.usedrange.rows.count
iColumns=activesheet.usedrange.Columns.count

'如果表格前面的几行或几列可能是空的,需要获得最下面的行数和最右面的列数:
with activesheet.usedrange
iEndRow=.rows.count+.row-1
iEndColumn=.Columns.count+.column-1
end with

回答2:

Sub test1()
A = ActiveCell.Row
B = ActiveCell.Column
MsgBox A & "行," & B & " 列", vbInformation
End Sub