9tanstaafl9
Well-known Member
- Joined
- Mar 23, 2008
- Messages
- 535
I frequently have to clean up phone numbers for data import. I got everything to work perfectly, EXCEPT for the rare instances where there might be more than one delimiter between a phone number and an extension. So these work fine:
444-444-4444 ext: 2345
333-1111 #2224456 cindy
But this doesn't
333-333-3333 ##2345
In the latter case, the TextToColumns would separate the data into 3 columns not two, and would overwrite an entire column of data that I need to keep.
So my question, is there any way to modify my code so that it can't split data into more than the selected column and the column to the right?
I don't care how the extension field will be formatted. I just want to save the information so that it is available.
444-444-4444 ext: 2345
333-1111 #2224456 cindy
But this doesn't
333-333-3333 ##2345
In the latter case, the TextToColumns would separate the data into 3 columns not two, and would overwrite an entire column of data that I need to keep.
So my question, is there any way to modify my code so that it can't split data into more than the selected column and the column to the right?
Code:
'attempts to split out extensions entered into phone field
On Error Resume Next
With Selection
.Replace "~*", "§", xlPart
.Replace "#", "§", xlPart
.Replace "extension", "§", xlPart
.Replace "ext:", "§", xlPart
.Replace "ext", "§", xlPart
.Replace "ex", "§", xlPart
.Replace "x", "§", xlPart
.Replace ":", "§", xlPart
.TextToColumns other:=True, OtherChar:="§"
End With
'Removes nonnumeric cells and formats number correctly
On Error Resume Next
Dim c As Range
Dim i As Long
Dim sTemp As String
If Not TypeOf Selection Is Range Then Exit Sub
For Each c In Selection
sTemp = vbNullString
For i = 1 To Len(c.Value)
If IsNumeric(Mid(c.Value, i, 1)) Then sTemp = sTemp & Mid(c.Value, i, 1)
Next
c.Value = sTemp
If Len(c) = 11 Then c = Right(c, 10)
c.NumberFormatLocal = "000 000-0000"
Next
I don't care how the extension field will be formatted. I just want to save the information so that it is available.