"Find" function in VBA possible to find the last occurance?

Peterso

Board Regular
Joined
Nov 28, 2012
Messages
102
I wrote set f=range("A:A").find(x). How should I modify to make it to find the last occurance? Thx
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
If your wanting to find the last row in column "A" with data use this:
Code:
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
 
Upvote 0
Like this perhaps?

Code:
myFind = "Hello"
Set c = Columns("A").Find(What:=myFind, After:=Range("A" & Rows.Count), LookAt:=xlWhole, SearchDirection:=xlPrevious)
 
Upvote 0
Slight difference to Steve the fish code...
Code:
Set f = Columns("A").Find(What:="x", After:=[A1], LookAt:=xlWhole, SearchDirection:=xlPrevious)
Reason for change is the next cell after A1 using xlPrevious is the last cell in the range.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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