Find last used row problem

Brian.Crawford

Board Regular
Joined
Oct 3, 2007
Messages
136
I have the following section of code from a SUB that needs to know the last row with data in it.
.
Dim RwCount as long, RRng as range
.
.
With Sheets("annualsummary")
Set RRng = .Range("D:D")
RwCount = RRng.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.
.
When the code is executed during normal VBA macro execution the RwCount is returned =0. When I step through the code with the debugger I get the correct answer of 171. I use this last row method extensively in my macros and up until a week ago it has always worked. I have only seen this problem in this particular SUB/macro.

The following setting are in place (and have been all along)
Calculation is set to manual
EnableEvents is false
ScreenUpdating is false

Any advice is much appreciated.
Brian
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
some solutions

lastrow1 = Range("D1").End(xlDown).Row
lastrow2 = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row
lastrow3 = ActiveSheet.UsedRange.SpecialCells(xlLastCell, xlNumbers).Row
lastrow4 = Cells(Rows.Count, "D").End(xlUp).Row
lastrow5 = Cells(Rows.Count, 4).End(xlUp).Row
lastrow6 = Range("D" & Rows.Count).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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