Is there a VBA wildcard for non-numeric characters only?

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,504
Office Version
  1. 365
Platform
  1. Windows
I want to know whether a string is Like "#???" or Like "##??"

But the question marks here need to be text only. I am only looking for a number followed by three non-numeric characters (i.e. text) or two numbers, followed by two non-numeric characters. How can I achieve this? Right now Excel is not knowing the difference because the question mark stands for "any character" - so what can I use as a wildcard to look for only non-numeric characters?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I want to know whether a string is Like "#???" or Like "##??"

But the question marks here need to be text only. I am only looking for a number followed by three non-numeric characters (i.e. text) or two numbers, followed by two non-numeric characters. How can I achieve this? Right now Excel is not knowing the difference because the question mark stands for "any character" - so what can I use as a wildcard to look for only non-numeric characters?
I assume we are talking about the Like operator in VBA. The answer kind of depends on what you mean by non-numeric. Are you including punctuation marks as non-numeric or alphabetic letters only? I'll assume alphabetic letters (either upper or lower case). For your first part...

Like "#[A-Za-z][A-Za-z][A-Za-z]"

and for your second part...

Like "##[A-Za-z][A-Za-z]"
 
Upvote 0
Or you could do both parts together with:

Code:
Like "#[0-9A-Za-z][A-Za-z][A-Za-z]"

but it does depend on what you mean by "non-numeric characters". If you mean any non-numeric character then you might prefer this:

Code:
Like "#?[!0-9][!0-9]"
 
Upvote 0

Forum statistics

Threads
1,215,527
Messages
6,125,337
Members
449,218
Latest member
Excel Master

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