Get last used row in worksheet

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,131
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
According to various posts this should work
LastRowNum = Cells(Rows.Count, 1).End(xlUp).Row
In my sheet it returns 27 even though there is data in Row 28 but not in Column 1.
Is there a method to find the last row with data in any column? It could be any col from A to S.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
try this:

=SUMPRODUCT(MAX((P:P<>"")*ROW(P:P)))

you need to adjust P in my example to match your row you are looking at....
 
Upvote 0
Thanks @Holger, can you tell me how to run that in a module? I think it's something like App.WorksheetFunction = .
I've never use it before.
 
Upvote 0
If you don't have a column that is reliably always going to have data in it then the Find method tends to be the preferred method.

VBA Code:
    Dim LastRowNum  As Long
    LastRowNum = Cells.Find(What:="*", _
                    After:=Range("A1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious, _
                    MatchCase:=False).Row
                    
    Debug.Print LastRowNum
 
Upvote 0
Solution

Forum statistics

Threads
1,225,969
Messages
6,188,112
Members
453,460
Latest member
Cjohnson3

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