12,299,210 members (39,595 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 20: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
 ppolymorphe 345 OriginalGriff 308 CHill60 176 George Jonsson 170 Karthik Bangalore 115
 OriginalGriff 9,733 ppolymorphe 5,826 CHill60 5,452 Karthik Bangalore 5,056 Richard MacCutchan 4,894