Format Cells for Driver's License numbers

joy947

New Member
Joined
Mar 27, 2009
Messages
3
I am trying to format cells to show driver's license numbers as:

S-123-456-789-012

The DL #s currently are showing as a couple of different general entries - such as:

S123456789012 or
S123-456-789-012

How can I have excel change from the current format of varying entries to a standard entry as S-123-456-789-012?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Since it is an alphanumeric string, you can't use a custom format. You'll need to either use VBA to automatically replace the value with the formatted one (hard-coding in the dashes) or you'll need to have a formula in another column to insert the dashes for you, storing the value as a string.
 
Upvote 0
This function will do what you want at the expense of an extra column in your worksheet:-
Code:
[FONT=Courier New][SIZE=1]Option Explicit[/SIZE][/FONT]
[FONT=Courier New][SIZE=1][/SIZE][/FONT] 
[FONT=Courier New][SIZE=1]Public Function Reformat3x4(argString As String) As String[/SIZE][/FONT]
[FONT=Courier New][SIZE=1][/SIZE][/FONT] 
[FONT=Courier New][SIZE=1]  Dim strTemp As String
  
  strTemp = Replace(argString, "-", "")
  strTemp = Left(strTemp & String(13, "?"), 13)
  strTemp = Left(strTemp, 1) _
          & "-" & Mid(strTemp, 2, 3) & "-" & Mid(strTemp, 5, 3) _
          & "-" & Mid(strTemp, 8, 3) & "-" & Mid(strTemp, 11, 3)
         
  Reformat3x4 = strTemp[/SIZE][/FONT]
[FONT=Courier New][SIZE=1][/SIZE][/FONT] 
[FONT=Courier New][SIZE=1]End Function[/SIZE][/FONT]
If your licence number is in A1, use the formula =Reformat3x4(A1) to produce a reformatted version. There's very little error-checking - only the length is checked and if it's not thirteen characters, it gets padded with question marks. If you need more error-checking, that's easily incorporated.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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