Formatting entry into a cell.

Hagaar

New Member
Joined
May 14, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi there, I know this will be sooo basic for all of you but this is driving me mad.

I want to force the correct entry of a UK driving licence number which is 16 digits. I want it to display in the cell as XXXXX XXXXXX XXXXX The first group of five can be alphanumeric, the next group of 6 must be numbers and the last group of 5 are alphanumeric. I would like a space to show between the groups of numbers for ease of reference.

I hope you can help me. I did try and use the search facility but unless you know how to word the search it does not come up with what I need.

Thanks in anticipation.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Do you have other information to validate the number against?

Last name, initials, date of birth and gender?
 
Upvote 0
Hi, I do not need to validate any other data. I just want to make sure that the person entering the number is forced to enter the correct amount of digits and that they are then displayed as xxxxx xxxxxx xxxxx. It’s so simple I can’t believe I can’t find how to do it.

Thank you for your help.
 
Upvote 0
Welcome to the forum!

You can potentially use Data Validation to restrict users from entering bad data. In this example, they will be entering the code in A3. First format A3 as text. Then select Data Validation from the Data tab and enter the custom formula as shown. Displaying it as a 5-6-5 format is trickier, since there isn't a built-in format for that. The best I could do was to use a formula in the B3 cell to display it as you want.

Book1
AB
3abcde123456abcdeabcde 123456 abcde
Sheet21
Cell Formulas
RangeFormula
B3B3=LEFT(A3,5)&" "&MID(A3,6,6)&" "&RIGHT(A3,5)
Cells with Data Validation
CellAllowCriteria
A3Custom=AND(LEN(A3)=16,ISNUMBER(MID(A3,6,6)+0))


Also note that it's easy to defeat Data Validation. If someone tries to copy and paste a value in the A3 cell, it will accept it. Only manually entered values are checked. You can potentially use VBA (a macro) to provide something a bit stronger.
 
Upvote 0
Hi, I do not need to validate any other data.
That's not what I asked.

As Eric has pointed out, there are flaws in attempting to validate the format correctly. If you have all of the information that I mentioned then that can be used to validate (or even generate) the first 13 characters accurately.
 
Upvote 0
See example, although I haven't figured out how to fit this into data validation successfully,

Book1
ABCDEF
1Last nameFirst NameMiddle NameDOBGender
2SmithJohnJohn01/02/2003MSMITH002013JJ
3DoeJane10/10/2010FDOE99160100J9
Sheet16
Cell Formulas
RangeFormula
F2:F3F2=LEFT(SUBSTITUTE(UPPER(A2),"MAC","MC")&999,5)&LEFT(TEXT(D2,"yy"))&TEXT(MONTH(D2)+IF(E2="F",50),"00")&TEXT(D2,"dd")&MOD(YEAR(D2),10)&LEFT(LEFT(B2)&LEFT(C2)&9,2)
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

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