brandoda22
New Member
- Joined
- Sep 7, 2007
- Messages
- 11
I have this script that does what i need it to do but one thing, I need the script to count the numbers as digits only and not the dashes in the format.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub
If Intersect(Target, Range("I21:I24")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False
If (Len(Target) > 11) Or (Len(Target) < 10) Then
MsgBox "Not a valid number of characters, please try again"
Target.Value = vbNullString
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
End If
If Len(Target) = 10 Then Target.Value = Format(Target, "###-###-####")
If Len(Target) = 11 Then Target.Value = Format(Target, "##-###-##-####")
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub
If Intersect(Target, Range("I21:I24")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False
If (Len(Target) > 11) Or (Len(Target) < 10) Then
MsgBox "Not a valid number of characters, please try again"
Target.Value = vbNullString
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
End If
If Len(Target) = 10 Then Target.Value = Format(Target, "###-###-####")
If Len(Target) = 11 Then Target.Value = Format(Target, "##-###-##-####")
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub