E
excel user
I need to create a custom number format for a wisconsin driver's license
number (i.e. "S123-4567-8912-34") How can this be done?
number (i.e. "S123-4567-8912-34") How can this be done?
I need to create a custom number format for a wisconsin driver's license
number (i.e. "S123-4567-8912-34") How can this be done?
driver's
license numbers in their correct format. They should have the formats
pre-defined just as they do with "Social Securtiy Number" and "Zip Code".
Dave Peterson said:You could use a worksheet_Change event.
Rightclick on the worksheet tab that should have this behavior. Select view
code. Paste this into the code window that just opened:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRngToCheck As Range
Dim myIntersect As Range
Dim myCell As Range
Dim myStr As String
Set myRngToCheck = Me.Range("a:a")
Set myIntersect = Intersect(Target, myRngToCheck)
If myIntersect Is Nothing Then
Exit Sub
End If
On Error GoTo ErrHandler:
Application.EnableEvents = False
For Each myCell In myIntersect.Cells
myStr = ""
If UCase(myCell.Value) Like "[A-Z]#############" Then
'do the conversion
myStr = UCase(Left(myCell.Value, 1)) _
& Format(Mid(myCell.Value, 2), "000-0000-0000-00")
myCell.Value = myStr
End If
Next myCell
ErrHandler:
Application.EnableEvents = True
End Sub
I checked all of column A. Change this line to match your input range:
Set myRngToCheck = Me.Range("a:a")
excel said:That's unfortunate. You'd think MS would have the ability to store driver's
license numbers in their correct format. They should have the formats
pre-defined just as they do with "Social Securtiy Number" and "Zip Code".
It's pretty rare I find something that MS Excel cannot do. What about using
an event driven macro - would that work? How would it work? Would you be
able to use the same cell?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.