Excel VBA Range.Find not finding occurrence

lexxie2013

Board Regular
Joined
Nov 28, 2013
Messages
225
Hi all. Pls could someone explain what I'm doing wrong. If I have 'Yes' in Cell A1 and 'Yes' in any other cell in Column A, the MatchVenue.Row returns the second instance rather than the first. Is there an optional header parameter that I've overlooked. I've looked at Microsoft documentation but failed to find an answer. Any help would be much appreciated.

<code>
Dim MatchVenue As Range
VenueName = "Yes"
Set MatchVenue = ThisWorkbook.Sheets("Sheet1").Columns(1).Find(What:=VenueName, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
MsgBox (MatchVenue.Row)
</code>

Thanks,

Steve.
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
have you tried xlpart instead of xlwhole
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,390
Office Version
  1. 2019
Platform
  1. Windows
Hi,
You have omitted the After argument so the search starts in the upper left hand corner of the range. Your search begins AFTER this range & as a match has been found in the range, your code returns that result.

This is fully explained in the VBA helpfile:
https://msdn.microsoft.com/en-us/library/bb178845(v=office.12).aspx

If you want to return all matches in your range, you would need to include FindNext Method which again, you can read about in the VBA helpfile which gives a working example.
https://msdn.microsoft.com/en-us/library/office/ff196143(v=office.15).aspx

Hope Helpful

Dave
 
Last edited:

lexxie2013

Board Regular
Joined
Nov 28, 2013
Messages
225
Thanks Dave,

I'd overlooked the After argument in the documentation. That's certainly given me a solution. Ta.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,320
Messages
5,600,940
Members
414,417
Latest member
Nobu

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