Here's a simple routine for LastRow, LastColumn
chris a écrit :
I put together a simple routine that will find the last Row and last Column w/ data in a spreadsheet.
Without the pitfalls and limitations of:
End(xlup), End(xlDown) and "simple" UsedRange.
Any critique is welcomed.
Sub LstRow_LstColumn()
Dim Rw As Range, Clm As Range
Dim x As Single, LRw As Single, LClm As Single
If WorksheetFunction.CountA(ActiveSheet.UsedRange) = 0 Then Exit Sub
With ActiveSheet.UsedRange
Do
x = x + 1
Set Rw = .Offset(.Rows.Count - x).Resize(1)
Loop Until WorksheetFunction.CountA(Rw) < 0
LRw = Rw.Row
x = 0
Do
x = x + 1
Set Clm = .Offset(0, .Columns.Count - x).Resize(, 1)
Loop Until WorksheetFunction.CountA(Clm) < 0
LClm = Clm.Column
End With
End Sub
Hi Chris,
I use these to find out :
* last row
Lx = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
* last column
Cx = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
The very last cell as address (sheet starting in A1) :
MsgBox Cells(Lx, Cx).Address
HTH
@+
FxM
|