Zip Code Macro

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Greegan (greegan_at_mts.net)
Date: 12/08/04


Date: Wed, 8 Dec 2004 23:02:06 -0000

Again, thanks for all your help so far...
And thanks in advance for this one.

I have zip codes in Column I
I have the Country Code (CA for Canada, GB for England and such, and US for
...) in Column H

As you know some zip codes for the US can have a 5 or 9-digit format 90210
and 90210-1111 (for example although I know that is not a true code).
However some zip codes we will have appear in Column I will have only 4 or
even 3 digit zip code (latter example for PR) and we will use the Format
cell Special Zip Code.
For this fact we will not select Column I and Format Cell Special Zip Code+4
as the extended digits will only appear as zeroes...

So our only solution is to remove the last four digits on the Right hand
side of the 9-digit zipcodes (beit 30%, 50%, or 90% of the whole column).

Currently my solution is this:
Copy and Insert copied column into J from I (so i have two zip code columns)
Then I use =len(I1) and fill down.
I sort by descending order and find all the 9-digit zips
Text to Column Fixed length to 5 characters.
Then 8-digit zips are fixed to 4 characters and so on (each time cutting off
4 digits) - only done to 7 digits and left with 3 fixed (for PR zips).

Now the macro I have below was done by a co-worker of mine that seemed to
work but I have since found errors with the resulting zip codes.

If you can suggest something please do.
Keep in mind that I only want these fixed lengths IF "US" is in column H.

I'm actually looking for a macro for two scenarios:
Column I (zip codes) and Column H (Country)
and a second macro doing the same action but with the following changes
Column L (zip codes) and Column S (Country)

The macro below was meant to work with the former.

I'm looking for a simpler way to do this.

Sub SWO_ZipCods9()
'
' MY_ZipCods9 Macro
' Macro recorded 03/10/2004 by Scott Beattie
'
' Changes nine-character zip codes to five or less cutting off the four
digits to the right only if the country code column contains "US"
'
    Cells.Select
    Selection.Sort Key1:=Range("I1"), Order1:=xlAscending, Header:=xlGuess,
_
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Columns("I:I").Select
    Selection.Copy
    Columns("J:J").Select
    Selection.Insert Shift:=xlToRight
    Application.CutCopyMode = False
    Range("J1").Select
    ActiveCell.FormulaR1C1 =
"=IF(RC[-2]<>""US"",RC[-1],INT(LEFT(RC[-1],5)))"
    Range("J1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.FillDown
    Selection.FillDown
    Columns("J:J").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
        :=False, Transpose:=False
    Columns("I:I").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    Selection.NumberFormat = "00000"
End Sub



Relevant Pages

  • NANP Things (US Toll Free from Toronto)
    ... All of the other non-US Caribbean islands which are part of the NANP ... The numeric digits of their ITU Country Code were retained as the ... > countries as '14' in each case followed by thier area codes or other ...
    (comp.dcom.telecom)
  • Re: Mexico (Dial 1)
    ... country code) area codes could be reassigned forever. ... The NANPA website reports 328 area codes are ... The 278 USA NPAs can be further broken down as: ...
    (comp.dcom.telecom)
  • Re: Formular
    ... If the country code is in A1 and the comma-separated dialling codes in B1, ... containingg Dial codes, in which you can find too many dial codes in one ... each Dial code in another Column that are separated by Commas??? ...
    (microsoft.public.excel.misc)
  • Re: A Question About International Country Code Number Assignments
    ... What logic lies in this order of ... The codes are assigned by an office at the International ... ITU recommendation E.164 describes country code allocation, ...
    (comp.dcom.telecom)
  • Re: Man, I am in DESPERATE need of a macro
    ... as it stood as Ras hadn't said what else was in the document. ... I just opened a new macro and pasted it in and expected it to run. ... T100 all of a sudden I need to make T102 but, to ensure the codes stay ... I need to manually go down the column and bump ALL codes by 2 ...
    (microsoft.public.word.vba.general)