VBA search on cell value with wildcard

Dave8899

New Member
Joined
Jan 17, 2019
Messages
32
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

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,)
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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