SOLVED!
Hey I am trying to include dashes into an identification number based on the number of characters in the cell. For example I want to turn A12010 to A1-20-10 or A120010 to A1-200-10.
The identification numbers will only ever be 6 or 7 characters long with the first and last two characters being separated by dashes. Here is my code
Sorry I am new to this. Is this not a correct approach?
Hey I am trying to include dashes into an identification number based on the number of characters in the cell. For example I want to turn A12010 to A1-20-10 or A120010 to A1-200-10.
The identification numbers will only ever be 6 or 7 characters long with the first and last two characters being separated by dashes. Here is my code
Code:
Sub ReplaceDash()
Dim Cell As Range
For Each Cell In Selection
If Len(Cell) = 6 Then
Cell.Value = Left(Cell,2) & "-" & Mid(Cell,3,2) & "-" Right(Cell,2)
ElseIf Len(Cell) = 7 Then
Cell.Value = Left(Cell,2) & "-" & Mid(Cell,3,3) & "-" Right(Cell,2)
End If
Next
End Sub