12,816,490 members (33,910 online)
Rate this:
See more:
Hi,

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.

Sunny K
Posted 14-Jun-12 21:21pm
ryanb31 15-Jun-12 9:09am

You could also loop through each cell and use the LEN() function instead.
Sunnykumar08 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 :)

Rate this:

## Solution 1

I haven't tested it, but trying specifying 21 just once, like so:

`^[a-zA-Z0-9]{21}\$`
Sunnykumar08 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 11-Jul-12 20:05pm

If you want alphanumeric values you should write somthing like this:
^[\w\,]{21}\$

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.

Top Experts
Last 24hrsThis month
 Richard Deeming 200 Karthik Bangalore 179 Jochen Arndt 175 Dave Kreskowiak 150 ppolymorphe 120
 OriginalGriff 4,427 Graeme_Grant 3,649 Karthik Bangalore 3,386 Jochen Arndt 2,391 ppolymorphe 2,387