Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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.

Thanks in Advance,
Sunny K
Posted
Comments
ZurdoDev 15-Jun-12 9:09am    
You could also loop through each cell and use the LEN() function instead.
Sunny_Kumar_ 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

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

^[a-zA-Z0-9]{21}$
 
Share this answer
 
Comments
Sunny_Kumar_ 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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900