Use Like or RE

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,099
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I'm wanting to identify a string that starts with one char A to Z, then any number, than a period and space.

I *think* LIKE [A-Z][1-9]. *" could be be a starting point but I'm not sure if I'm getting confused with Regular expressions, plus how to handle a number > 9.

Thanks for any help
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I'm wanting to identify a string that starts with one char A to Z, then any number, than a period and space.

I *think* LIKE [A-Z][1-9]. *" could be be a starting point but I'm not sure if I'm getting confused with Regular expressions, plus how to handle a number > 9.

Thanks for any help

If your variable name is Code then try this...

If Code Like "[A-Z]" & String(Len(Code) - 3, "#") & ". " Then
 
Last edited:
Upvote 0
Hi Rick,
I'm finding it fails if CODE has characters after ". "
 
Upvote 0
Hi Rick,
I'm finding it fails if CODE has characters after ". "
Sorry, I forgot you said "starts with"... we just need to add an asterisk (wildcard) at the end of the pattern...

If Code Like "[A-Z]" & String(Len(Code) - 3, "#") & ". *" Then
 
Last edited:
Upvote 0
I did try that Rick, and still couldn't make it work here

? code
A1. This is a Test
? Code like "[A-Z]" & string(len(code)-3, "#") & ". *"
False

So I resorted to RE with

regex.Pattern = "^[A-Z][0-9]+\.\s"
 
Upvote 0
I did try that Rick, and still couldn't make it work here

? code
A1. This is a Test
? Code like "[A-Z]" & string(len(code)-3, "#") & ". *"
False
Sorry, my fault. Try your If..Then statement this way...
Code:
[table="width: 500"]
[tr]
	[td]If Split(Code, ". ")(0) Like "[A-Z]" & String(InStr(Code & ". ", ". ") - 2, "#") Then[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Hi Rick, that now works, but I found code = "AB. This is a Test" would also pass, when it should fail.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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