Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Excel VBA RegEx
I want to verify the characters entered in excel sheet' cell using vba. I'm trying this with the pattern "^[a-zA-Z0-9]{21,21}$". I want this to match exactly 21 characters (can be alphanumeric) and no more or less than that. Its working fine when the characters are less than 21 characters but not when they exceed. Please suggest me how could I achieve that.
I appreciate any help.
Thanks in Advance,
Sunny K
Posted 14-Jun-12 20:21pm
ryanb31 at 15-Jun-12 9:09am
You could also loop through each cell and use the LEN() function instead.
Sunnykumar08 at 16-Jun-12 5:14am
Hi ryanb, thanks for the suggestion. I'm already using this trick, but it's an overhead counting the characters every time if we're using a Regular expression to match. I want a definite solution. Thanks if you may assist me this way :)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I haven't tested it, but trying specifying 21 just once, like so:
Sunnykumar08 at 16-Jun-12 3:35am
Hi Rick, I appreciate your help, but I already have given this a try but this didn't do the trick.
Kenneth Haugland at 11-Jul-12 20:05pm
If you want alphanumeric values you should write somthing like this:
I only got matches if it had exactly 21 repititions. I fthis dosent work I would think that you have forgotten to add som of the charecters you search for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 383
1 OriginalGriff 304
2 George Jonsson 258
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,099
1 Sergey Alexandrovich Kryukov 5,411
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522

Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 15 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100