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.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
have you tried xlpart instead of xlwhole
 
Upvote 0
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:
Upvote 0
Thanks Dave,

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

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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