If then using a wildcard to search for text

fly2079

New Member
Joined
Feb 18, 2002
Messages
4
I am needing to loop through a series of cells and search for a criteria. The criteria could be something like 'C172' and I want to add that whole row to a range if the cell contains even just the 'C' part or just the '1' part etc. Is there a way to do a wildcard search in vba like
If Range("A:1").Value = "C*" so that I can do something if the value of the cell starts with 'C'?
This message was edited by fly2079 on 2002-02-19 07:56
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
On 2002-02-19 07:55, fly2079 wrote:
I am needing to loop through a series of cells and search for a criteria. The criteria could be something like 'C172' and I want to add that whole row to a range if the cell contains even just the 'C' part or just the '1' part etc. Is there a way to do a wildcard search in vba like
If Range("A:1").Value = "C*" so that I can do something if the value of the cell starts with 'C'?
This message was edited by fly2079 on 2002-02-19 07:56
You can try this:
Code:
If UCase(Left(Range("A1").Value, 1)) = "C" Then 'rest of your code
Note, this will work regardless of the case of the letter (i.e., "C" or "c") but you will get an error if A1 is numeric.
 
Upvote 0
Ok, now what do I do if I want to search for the numeral 1 or 7 or 172. What this I'm using this for is the user inputs values into a box and I want to have the option of searching for 'contains' in other words search for through and find if part of the value is in the cell. Is this a UDF?
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,184
Members
448,554
Latest member
Gleisner2

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