Find the last row with in a range, but stop once a given row or cell is reached

Tanner_2004

Well-known Member
Joined
Jun 1, 2010
Messages
616
I know there is a line of code that allows one to find the last row of a worksheet, and then work it's way to a row with a populated cell.

Let' say, I would to start of the bottom, but in my case the bottom is row 1000 and continue searchin upward (rows, 999, 998,.....) until reaching row 5 (including row 5). Then confine the search between columns D and Z, including Rows D and Z.


Does that make sense?

Thank you for reading. Your advice is always greatly appreciated and valued.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Something like this?
Cells(1000, "D").End(xlUp).Row
 
Upvote 0
That was excellent; I just watched it. But I still want to solve for the code that would allow me to do what I had first posted.Naturally, I will want to change the last row and first and last column, but once I learn how to do the former, I will just have to replace the row and columns numbers in the code with whatever I want.

Thank you!
 
Upvote 0
Maybe like this ??
But if this doesn't help and drsarao's tip didn't help...then you will need to provide more information on exactly what you want !!!
Code:
Sub MM1()
Dim lr As Long, r As Long, c As Integer
lr = Cells(Rows.Count, "D").End(xlUp).Row
For c = 4 To 23 'columns "D" to "Z"
    For r = lr To 5 Step -1 'lastrow to row 5
        if cells(r,c).Value = '"some value here" then
            'do stuff
        End If
    Next r
Next c
End Sub
 
Upvote 0
Or for last row and last column
Code:
Sub MM1()
Dim lr As Long, r As Long, c As Integer, lc As Integer
lc = Rows(1, Columns.Count).End(xlToLeft).Column
lr = Cells(Rows.Count, "D").End(xlUp).Row
For c = 4 To lc
    For r = lr To 5 Step -1
        if cells(r,c).Value = '"some value here" then
            'do stuff
        End If
    Next r
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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