VBA compare if number appears in text string?

sthrncaliguy

Board Regular
Joined
Jul 28, 2009
Messages
213
I am working on a macro that isolates rows that contain a specific number in one column. The number could be anything from 0 to 5. There is a userform where the user can select any combination of numbers from 0-5 to search for, and I am buildling a Variable String based on those check boxes...

So the variable might look like this: NumberStr = 01345, or
NumberStr = 135, or any other combination of 0, 1, 2, 3, 4, and 5.

What I need help with is the syntax to compare a cell value to that string.. So if the cell has a 1, 2, 3, 4, or 5 in it, and the String had a 0,1,2,3,4, or 5 in it, that cell would result in a True statement for VBA purposes.

I was thinking there was some type of InStr or [Character] function in VB, but I am having trouble locating any good examples showing the proper syntax to accomplish this.

Any help is appreciated.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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