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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,216,743
Messages
6,132,461
Members
449,729
Latest member
davelevnt

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