Find Last Instance Of A Word

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,066
Hi All,

I am after a script that will find the last instance of the word Yes within Column A of a worksheet.

The word Yes may be in column A 1000+ times and there are blank/ empty cells (non contiguous) in column A also.

I would run the code using a macro button on the spreadsheet.
I have several buttons that look for different words but I can modify a suitable script.

Thanks ;)
 
Thanks everyone,

rsxchin and didi's examples are what I am after, is there a way to make it non case sensitive as some results may be Yes or YES or yes.

Thanks.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
use UCase() function:

Code:
Sub LastYes ()
    for row=Cells(Rows.Count,1).End(xlUp).Row to 1 step -1
        if ucase(cells(row,1))="YES" then
            msgbox "last Yes is in row " &row
            exit for
        end if
    next row
end sub
 
Upvote 0
beautiful, thanks Diddi, exactly what I am after, have a great weekend in Shepparton.:laugh::laugh::laugh:
 
Upvote 0
Sorry Diddi, one last thing.

Can you please provide the code which will select the last cell which contains the yes also as that's actually what I am after.
 
Upvote 0
Hi Jaye7,

Just though I'd let you that Tom's code works really well, just need to change the reference from 'No' to 'Yes'

Regards,

Robert
 
Upvote 0
Thought I'd throw in my two cents worth (based in part from Tom's earlier posting):

Code:
Sub FindLast()

    Dim varMySearchItem As Variant
    Dim lngLastRow As Long
    
    varMySearchItem = "Yes"
    lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    If Application.WorksheetFunction.CountIf(Range("A1:A" & lngLastRow), varMySearchItem) > 0 Then
        Range("A" & Evaluate("MAX(IF(A1:A" & lngLastRow & "=""" & varMySearchItem & """,ROW(A1:A" & lngLastRow & ")))")).Select
    Else
        MsgBox "There were no matches for " & varMySearchItem & " found!!", vbExclamation, "Last Instance Editor"
    End If
    
End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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