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

Peterso

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

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,343
Office Version
  1. 2021
Platform
  1. Windows
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

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,849
Office Version
  1. 365
Platform
  1. Windows
Like this perhaps?

Code:
myFind = "Hello"
Set c = Columns("A").Find(What:=myFind, After:=Range("A" & Rows.Count), LookAt:=xlWhole, SearchDirection:=xlPrevious)
 
Upvote 0

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
15,035
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
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,191,166
Messages
5,985,050
Members
439,935
Latest member
Monty238

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
Top