Finding the last cell that matches criteria

brites

Board Regular
Joined
Aug 19, 2004
Messages
224
Hi folks!

Heres the deal: I have in column B a list (ascending) of status (ok, sold, out of order, damage, rent).
I wanna know what is the last row where "out of order" appears.
What is the code line for that?

Thx in advance!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
By "code line" do you mean VBA? If so

Code:
Sub FindLast()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("B" & i).Value = "out of order" Then Exit For
Next i
MsgBox "Found in row " & i
End Sub

Note: this will erroneously return 1 if "out of order" is not found.
 
Upvote 0
Hi Jonmo1, thanks for your help.
Actually I wanna do it inside my VBA and store it under "variable y".

To find the first one im using:
x = Application.WorksheetFunction.Match("out of order", Sheets("Management_DB").Columns(2), 0)

Something like that....
 
Upvote 0
VOG II,
thanks! that did it!
Im already using it... but just for education wise...

Isnt there a simple line like the one to find the first one via ".match"?
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

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