Consulting

Results 1 to 12 of 12

Thread: Transfer zip code to another column

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    11
    Location

    Question Transfer zip code to another column

    Hello,
    I need your help with a script:
    In my spreadsheet, in column E, starting at line 3 and going down, I have different postal code. Now what I want to do is that, if the 3 first digits from the postal code are followed by the same 3 last digits, in column F, it will write only the 3 first digits. If the 3 first are the same but the 3 last are not the same, it will write the entire postal code in column F.

    EX:

    "COL E" "COL F"
    C2B 4F9 C2B
    C2B 4F9 C2B
    C9T 3R4 C9T 3R4
    C9T 1J0 C9T 1JO

    I have an error on my script:
    Private Sub CommandButton3_Click()
    'For the postal code
    Sheets("TL Data ").Columns("F:F").Select
        Selection.Insert Shift:=xlToRight
        Range("F3").Select
         
        
        Set MaZone = Range("E3:" & Range("E65536").End(xlUp).Address)
    For Each x In MaZone
        x.Offset(0, 1) = Split(x, " ")(0)
        Set c = MaZone.find(Split(x, " ")(0))
            firstAddress = c.Address
            Do
                If x.Value <> c.Value Then x.Offset(0, 1) = x: Exit Do
                Set c = MaZone.FindNext(c)
            Loop While c.Address <> firstAddress
    Next
    End Sub
    It sais: Object variable or with block variable not set (run time error 91)

    And it has to to i think with that section of the code:
    firstAddress = c.Address
    Thanks for your help.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a sample to test the code?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Feb 2009
    Posts
    11
    Location
    Yes.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Is this correct?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Feb 2009
    Posts
    11
    Location
    I cant open the file because of the low speed Internet.
    Could you give me the code only for now please?
    I will open the spreadsheet later.
    Thanks again

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    No Code
    F3 =IF(E4=E3,LEFT(E4,3),"")
    G3 =IF(E4=E3,"",E4)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Regular
    Joined
    Feb 2009
    Posts
    11
    Location
    OK,
    In an other circumstance, it would of been perfect but now it doesn’t.
    Actually, if I could have all in the same column, it would be better. Maybe in VBA.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    In an other circumstance, it would of been perfect but now it doesn’t.
    Means nothing to me.
    Actually, if I could have all in the same column, it would be better.
    Just combine the two formulae into one.
    Maybe in VBA.
    Why?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Feb 2009
    Posts
    11
    Location
    Because that file his an official file that i cant modified since the script that follows that, it transfer into notepad, and then transferred on the server.

  10. #10
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    Quote Originally Posted by wilder
    In an other circumstance, it would of been perfect but now it doesn’t.
    LOL?!

  11. #11
    VBAX Regular
    Joined
    Feb 2009
    Posts
    11
    Location
    forget it, I will find the solution myself.

    If this is to make the world laugh.

    Thank you anyway

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you need further asstance, please be specific. There is nothing in your responses which would guide me to your requirements.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •