Wednesday, August 27, 2008

Get Last Used Row

Sub get_last_used_row()
' to get the last non-blank row

LastRow1 = Cells(Cells.Rows.Count, "A").End(xlUp).Row
'this is the keyboard equivalent of selecting a range using shift and down arrow
'   Exercise What does "A" signify??

LastRow2 = UsedRange.Rows.Count

MsgBox "LastRow1 " & LastRow1
MsgBox "LastRow2 " & LastRow2

End Sub

Exercise - What is the difference between LastRow1 and LastRow2. Though they might give same results occasionally, the approach to get the last row is different. Find it out!


3 comments:

Kirubakaran A said...

I use:

r1 = Worksheets(sheet_name)
.Range("A65536").End(xlUp).Row

Ruchi said...

Thanks for sharing, Kirubakaran. This is simpler version of LastRow1.

You are the lucky winner of "Single Best Comment" ! I invite you to be my Guest Blogger for Tuesday 09/02?

Kirubakaran A said...

:-) Thanks