Using [0-9]

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,705
I think I'm getting confused with LIKE and Regular Expressions.
MyString contains a backslash followed by any 4 digits.
Code:
if MyString LIKE  "\" & "[0-9]"  then...
is failing.
I can think of many ways to resolve this but keen to know where I'm going wrong.

Thanks.
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,314
Office Version
  1. 2010
Platform
  1. Windows
I think I'm getting confused with LIKE and Regular Expressions.
MyString contains a backslash followed by any 4 digits.
Code:
if MyString LIKE  "\" & "[0-9]"  then...
is failing.
I can think of many ways to resolve this but keen to know where I'm going wrong.
Assuming there might be other text besides the backslash and four digits, try that line of code this way...

If MyString Like "*\####*" Then...
 

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
1,705
Thanks Rick, never knew you could use a hash char that way. Can't fault it.
And on further thinking I don't need "*" so Like "\####" tests okay too.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,042
Messages
5,526,420
Members
409,701
Latest member
nitmani

This Week's Hot Topics

Top