VBA search on cell value with wildcard

Dave8899

New Member
Joined
Jan 17, 2019
Messages
30
Hi hope someone can help I have a vba that is working really well but i need to modify it slightly, currently it’s searching dependent on the value of a cell,

VBA Code:
 searchvalue = reportsheet.Range (”C2”) .Value

this works fine if the content in “C2” is exactly right, but I’m using for ref numbers and they are long and complex is there a way to add a wild card or something so the vba will search for all matches, for example :

If C2 was 357, the vba would pick up 357, 2357, 3579, etc.

hope I’ve explained this enough if you want or need more let Me know

many thanks

dave8899
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Anthony47

Well-known Member
Joined
Mar 29, 2006
Messages
2,237
What is important is not the way you set the value for variable "searchvalue" but how you compare the target values with searchvalue, that you didn't show us.
So I can suggest that you use not (for example) If Something = searchvalue Then but use operator Like
For example:
VBA Code:
If Something Like "*" & searchvalue & "*" Then
For the description of Like: Like operator


Or you might use the function InStr; for example:
Code:
If InStr(1, Something, searchstring, vbTextCompare) > 0 Then
For the description of InStr: InStr function (Visual Basic for Applications)

If these suggestions don't help, then share the relavant part of your code

Bye
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,350
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA search on cell value with wildcard
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 

Forum statistics

Threads
1,141,398
Messages
5,706,207
Members
421,433
Latest member
yash0468

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