jonnyscott
New Member
- Joined
- May 11, 2005
- Messages
- 7
Hi there guys,
Really hoping someone might be able to help me here. I know there have been questions about Telephone numbers before, but I haven't found any that have the issue that I've got.
I have a number of records on phone numbers (around 3500), I know that it is possible to format the cells with Custom formats etc, however I have the phone numbers in various lengths some 7 digits, some 8, etc and I want to try and standardize it all to the same format.
The reason for the different lengths varies depending on who put them into the sheet,
Some records have country at the start eg +64 some of which are missing the +,
Some records have no country code but have the area code of the city, eg. 03, or 04 (some of which are missing the 0)
There is also at the end of some of these cells the extension number for the person, this too has also been put in by various people with different formats, eg. ext, extn, Ext, x, Ext. and Extn: however I've sorted this using a macro to change these all to just be Ext:
Example:
35551234
035551234
(03) 555 1234, Ext: 5678
+64 3 555 1234
+643 555 1234
+643 5551234, Ext: 567
03 555 1234
03 555-1234
03 684 4129
03-5551234
03-555-1234, Ext: 5678
64 3 555 1234, Ext: 567
As you can see there are a number of different formats, and as I've also mentioned, some of these may or may not be followed by , Ext: and their extension number
These above I think are the majority of the problems
I have a VBA script that goes through and converts all the wrong extension related stuff to the way I want it, and I have tried to get it.
However I'm a bit stuck for when I want it to change the area code to add the Zero in front or adding a + at the start, as well as the spaces in the wrong place, Ideally I would like things in the following format
I've found that with the cells that contain text as well, that the leading zero stays, however the cells that don't have text as part of them loose the leading Zero.
+64 3 555 1234, Ext: 5678
If someone could help me out here it would be appreciated. The code I have at the moment is as follows, note that the Colomn H is the colomn that has all the telephone numbers, and yes I know there is probably a much better way for doing all this, if so, please let me know.
Private Sub Worksheet_Activate()
Range("A1:K5001").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
'Begin Changing Telephone numbers
Columns("H:H").Select
'Remove all Gaps
'First one to replace Dash used to represent Extensions
Selection.Replace What:=" - ", Replacement:=" Ext: ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Replace X used for extension before spaces removed
Selection.Replace What:=" x ", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Change front of phone number
Selection.Replace What:="+64", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="(", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="(0", Replacement:="+64 ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Standardise Extension
Selection.Replace What:="Ext:", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="ext.", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="ext", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="extn:", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="extn", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Standardise Ext to Ext:
Selection.Replace What:="orExt", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=",Ext", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="Ext", Replacement:=", Ext: ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("B2").Select
Range("A1").Select
End Sub
Really hoping someone might be able to help me here. I know there have been questions about Telephone numbers before, but I haven't found any that have the issue that I've got.
I have a number of records on phone numbers (around 3500), I know that it is possible to format the cells with Custom formats etc, however I have the phone numbers in various lengths some 7 digits, some 8, etc and I want to try and standardize it all to the same format.
The reason for the different lengths varies depending on who put them into the sheet,
Some records have country at the start eg +64 some of which are missing the +,
Some records have no country code but have the area code of the city, eg. 03, or 04 (some of which are missing the 0)
There is also at the end of some of these cells the extension number for the person, this too has also been put in by various people with different formats, eg. ext, extn, Ext, x, Ext. and Extn: however I've sorted this using a macro to change these all to just be Ext:
Example:
35551234
035551234
(03) 555 1234, Ext: 5678
+64 3 555 1234
+643 555 1234
+643 5551234, Ext: 567
03 555 1234
03 555-1234
03 684 4129
03-5551234
03-555-1234, Ext: 5678
64 3 555 1234, Ext: 567
As you can see there are a number of different formats, and as I've also mentioned, some of these may or may not be followed by , Ext: and their extension number
These above I think are the majority of the problems
I have a VBA script that goes through and converts all the wrong extension related stuff to the way I want it, and I have tried to get it.
However I'm a bit stuck for when I want it to change the area code to add the Zero in front or adding a + at the start, as well as the spaces in the wrong place, Ideally I would like things in the following format
I've found that with the cells that contain text as well, that the leading zero stays, however the cells that don't have text as part of them loose the leading Zero.
+64 3 555 1234, Ext: 5678
If someone could help me out here it would be appreciated. The code I have at the moment is as follows, note that the Colomn H is the colomn that has all the telephone numbers, and yes I know there is probably a much better way for doing all this, if so, please let me know.
Private Sub Worksheet_Activate()
Range("A1:K5001").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
'Begin Changing Telephone numbers
Columns("H:H").Select
'Remove all Gaps
'First one to replace Dash used to represent Extensions
Selection.Replace What:=" - ", Replacement:=" Ext: ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Replace X used for extension before spaces removed
Selection.Replace What:=" x ", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Change front of phone number
Selection.Replace What:="+64", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="(", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="(0", Replacement:="+64 ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'Standardise Extension
Selection.Replace What:="Ext:", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="ext.", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="ext", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="extn:", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="extn", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
' Standardise Ext to Ext:
Selection.Replace What:="orExt", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=",Ext", Replacement:="Ext", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="Ext", Replacement:=", Ext: ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("B2").Select
Range("A1").Select
End Sub