Alphanumeric with Character Length Restriction

Gajendran Yadhav

New Member
Joined
Sep 8, 2023
Messages
46
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Dear friends,

I'm working on a sheet where I've to fill data based on daily status of the work.

for each category of task, I'm having an Alphanumeric code of 16 digits.

for ease of understanding I've attached the screen shot of the particular coulmn.
1694405634436.png


Here in this workbook, I've Data Validation function in Column O and dependent data validation in Column P.
I've a macro program such that if value in Column O is changed after an initial entry, column P gets cleared off. [using clear contents( )]
Moreover, the entire sheet is Cut,, Copy & Paste protected by using a Macro that I found in other thread here.

In the Column Q [CNR], I want to make the 16 digit Codes that accepts only alphanumeric values. No dashes, no spaces or any other special characters including ? & *.
i.e., A-Z & 0-9.
Character length limitation - 16.

Any help will be appreciated. thanks.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
this will insure that the code is 16 characters long,
It does allow entries longer than 16 characters.
It also allows, for example ABCD13DECEMBER23

My approach is ..
Excel Formula:
=AND(LEN(Q6)=16,ABS(77.5-CODE(MID(Q6,ROW(INDIRECT("1:4")),1)))<13,ISNUMBER(-MID(Q6,ROW(INDIRECT("5:16")),1)))
 
Upvote 1
**** IGNORE - DOESN'T WORK CORRECTLY ALL THE TIME ****

I think this should work correctly (Peter's formula is shorter though)...
Excel Formula:
=ISNUMBER(SUMPRODUCT(FIND(MID(F1,ROW(INDIRECT("1:4")),1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")))*ISNUMBER(-MID(F1,5,12))*(LEN(F1)<17)
 
Last edited:
Upvote 1
where should I add the LEN function to restrict the character length to 16
It would be
Excel Formula:
=AND(LEN(G1)=16,ISNUMBER(SUMPRODUCT(FIND(MID(G1,ROW(INDIRECT("1:"&LEN(G1))),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))))

But it could be done a bit shorter like this
Excel Formula:
=AND(LEN(G1)=16,COUNT(FIND(MID(G1,ROW(INDIRECT("1:16")),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))=16)

However, both of these take allow any combination of 16 digits or upper case letters (eg 1234567896549872). That is, hey do not take account of what you wrote in post #20
What if I need to use a different sequence say like WBCHCO0020272020 or TNKI0E0007472023 or any other combination...but always starting with alphabets and restricted to 16 characters long.

If you do actually require always starting with alphabets then since alphabets is written as plural, how many alphabets must be at the start?
 
Upvote 1
Solution
I figured out another way too...
Excel Formula:
=ISNUMBER(SUMPRODUCT(FIND(MID(Q5,ROW(INDIRECT("1:"&LEN(Q5))),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")))*(LEN(Q5)=16)
That really isn't another way. That is like saying
1+2=3 is different to 2+1=3
because * is another way of applying an AND function. So the two are basically identical, just written in a different order.
=AND(LEN(G1)=16,ISNUMBER(SUMPRODUCT(FIND(MID(G1,ROW(INDIRECT("1:"&LEN(G1))),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))))
=ISNUMBER(SUMPRODUCT(FIND(MID(Q5,ROW(INDIRECT("1:"&LEN(Q5))),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")))*(LEN(Q5)=16)


The other way that I suggested is still shorter though. ;)
=AND(LEN(G1)=16,COUNT(FIND(MID(G1,ROW(INDIRECT("1:16")),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))=16)
 
Upvote 1
You could simply control the column with a data validation
View attachment 98536
Thanks for your reply... I've enabled this option for Char Limitation of 16.
this doesn't control what characters I input... this accepts everything including "SPACE".

I want character restriction to A-Z & 0-9 only. no small cases / no other symbols etc.

In the data validation, by using this formula
=ISNUMBER(SUMPRODUCT(SEARCH(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
I'm able to control the character restriction to AA-Z & 0-9.
Is there any possibility to restrict the character length as well by using LEN()=16 in the above formula...
also the sequence of code I'm gonna use should contain both alphabets and numbers...
Eg: MHPU040061322016 ; TNMD100002612016 ; UPRP040190182018 etc...
 
Upvote 0
**** IGNORE - DOESN'T WORK CORRECTLY ALL THE TIME ****


I cannot test this because I do not have your version of Excel, but I think it should work. If I am right, this will insure that the code is 16 characters long, starts with 4 upper case letters and ends with 12 digits...
Excel Formula:
=ISNUMBER(SUMPRODUCT(FIND(MID(F1,ROW(INDIRECT("1:4")),1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")))*ISNUMBER(-MID(F1&"A",5,12))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,586
Members
449,520
Latest member
TBFrieds

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