Last Cell with Data over Entire Worksheet

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Hello all
Instead of finding a particular last row with data in a worksheet. I am exprimenting with finding the Last Cell with data over the entire worksheet, reguardless what row it is.
I have:
VBA Code:
'*********** Find Last Cell With Data **************
Dim LastCell As Range
Set LastCell = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
MsgBox = "Last Cell with Data Is  " & LastCell

However, I am getting the below error, and I'm not sure why.
What am I doing wrong?
Thank you for the help

1715118024152.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Remove the equal sign after MsgBox.
 
Upvote 0
If you want the cell address you would need to use
MsgBox "Last Cell with Data Is " & LastCell.Address

For the last row number
MsgBox "Last Cell with Data Is " & LastCell.Row

Note: rows hidden by a filter being applied will be ignored. Rows using Rows Unhide do not affect it and are still searched.
 
Upvote 0
Solution
If you want the cell address you would need to use
MsgBox "Last Cell with Data Is " & LastCell.Address

For the last row number
MsgBox "Last Cell with Data Is " & LastCell.Row

Note: rows hidden by a filter being applied will be ignored. Rows using Rows Unhide do not affect it and are still searched.
this is working well, thank you so much...
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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