Shortest Code for finding last row via VBA

nbrcrunch

Well-known Member
Joined
Jan 1, 2003
Messages
2,062
I'm wondering why the following doesn't seem to be encouraged on ANY Excel site I've ever seen. I've seen lots of code for determining the last row but this is the shortest. Is it error prone?

Sub Macro3()

Selection.SpecialCells(xlCellTypeLastCell).Select
TheLastRow = ActiveCell.Row
MsgBox (TheLastRow)

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
No, if you are using usedrange the only reliable way of resetting it is to close and reopen the workbook.
Quite often referring to the usedrange will reset it but I have known that to fail.
Application.volatile has nothing to do with the usedrange.
The Cells.Find method is the most reliable for me if looking for the last row with data on a sheet or Columns.Find for multiple columns.
 
Last edited:
Upvote 0
I don't think so. That has to do with telling functions (especially UDFs) to recalculate when ANYTHING in the worksheet is changed as opposed to (non-volatile) only when one of it's parent or child cells is changed. Has nothing (that I'm aware of) to do with code or updating what a line of code might evaluate.
 
Upvote 0
Deleted as reacted to a very old post on my phone :(
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,488
Messages
6,191,316
Members
453,653
Latest member
mvillasana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top