Conversion of 10 digit number into xx-xxx-xx-xxx
Try this. It will allow for multiple selections anywhere on the sheet. It
only addresses the first column of each selection, though. Enter the macro
in a general code module in the Visual Basic Editor.
Option Explicit
Sub Convert_Phone_Numbers()
Dim nAreas As Long, nRows As Long, i As Long, j As Long
Dim oldText As String, newText As String
'
nAreas = Selection.Areas.Count
'
For i = 1 To nAreas
nRows = Selection.Areas(i).Rows.Count
For j = 1 To nRows
oldText = Selection.Areas(i).Cells(j, 1).Text
newText = Left(oldText, 3) & "-" & Mid(oldText, 4, 3) & "-" &
Right(oldText, 4)
Selection.Areas(i).Cells(j, 1) = newText
Next j
Next i
End Sub
HTH,
Eric
"andreashermle" wrote:
Dear Experts:
I got a column of 10-digit numbers. They need to be converted like
this .....
Befo xxxxxxxxxx (10 digits)
After: xx-xxx-xx-xxx (10 digits separated by hyphens)
I would like to run a macro that does this conversion on selected
cells.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas
.
|