判断到哪里结束应该是Excel VBA最常见的操作之一,下面代码能实现这个功能:
- Function LastColumn() As Long
- Dim ix As Long
- ix = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count
- LastColumn = ix
- End Function
- Function LastRow() As Long
- Dim ix As Long
- ix = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
- LastRow = ix
- End Function
ref:
http://excelvbamacro.com/how-to-find-the-last-row-that-contain-data-in-excel.html
http://excelvbamacro.com/get-position-of-last-column-containing-data-with-excel-vba.html
转载于:https://blog.51cto.com/h2appy/825128