vba - find last instance of a text string

CROY1985

Well-known Member
Joined
Sep 21, 2009
Messages
501
Office Version
  1. 365
Platform
  1. Windows
Hi all

I have Some data which looks like this:

RowData
1Onions
2Onions
3Onions
4Potatoes
5Potatoes
6Potatoes
7Spring Onions
8Spring Onions
9Spring Onions

<tbody>
</tbody>


Im using the following vba code which isnt quite getting the right answer:

Code:
    Set where = C.Find(what:="Onions", after:=C(1), searchdirection:=xlPrevious)
    endrow = where.Row

But the vba code is finding the Onions in "Spring Onions" and returns row 9, i need it to match contents exactly and return row 3 in the example above.

Can anyone help on adjusting this?


Thank you
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try
Code:
Set Where = c.find("Onions", c(1), , xlWhole, , xlPrevious, False, , False)
 
Upvote 0
Try:
Code:
Dim endrow As Long
endrow = Range("C:C").Find("Onions", LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious).Row
Change "C:C" to suit your needs.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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