+ Reply to Thread
Results 1 to 7 of 7

Matching ZIP code with post name (VBA)

  1. #1
    Registered User
    Join Date
    02-21-2012
    Location
    Krsko, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    38

    Matching ZIP code with post name (VBA)

    Hello again!

    First of all thank you for everything and everybody that helped me with my problems. I have this big project work in my school and you guys are helping me alot.

    So, my problem is, that I have just ZIP codes from posts around Slovenia in sheet1(ZIP), and in sheet2 (DataBase) I have all ZIP codes from our country (column A) and post names that belongs to that code (column B). What I need is a VBA that would lookup all ZIP codes from sheet1(ZIP) in column B and write down name of the post in column C.

    Lets say that in column B is ZIP = 1000, in column C there would be name of the post(city) = Ljubljana

    I know that this I could do with VLookUP, but I need a macro for this, so that everytime there is a new database, I would simply clik on the button.

    Can anyone help me?

    Example: ExampleZIP.xlsx
    Last edited by Lynx2x; 03-05-2012 at 06:11 AM.

  2. #2
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Matching ZIP code with post name (VBA)

    Perhaps this way. See the attachement.
    Attached Files Attached Files
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  3. #3
    Registered User
    Join Date
    02-21-2012
    Location
    Krsko, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Matching ZIP code with post name (VBA)

    Thank you 1000 times!

    Works great and you have helped me alot, because my knowledge of VBA is really poor. I can now move on with my project.

    Thanks once again and have a great day!

  4. #4
    Registered User
    Join Date
    12-06-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Matching ZIP code with post name (VBA)

    This code works even better as there is no need to click a button. It basically updates automatically once the data is downloaded
    Simply copy and paste the 1st code in the ThisWorkbook module and the 2nd code in Sheet1(ZIP) module.

    Please Login or Register  to view this content.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    on error resume next
    i = WorksheetFunction.CountA(Range("c1:c1000"))
    u = WorksheetFunction.CountA(Range("b1:b1000"))

    If Sheets("zip").Range("b2").End(xlDown).Offset(0, 1) = "" Then _
    Sheets("zip").Range("b2").End(xlDown).Offset(0, 1).End(xlUp).AutoFill Destination:=Range("c" & i, "c" & u)

    End Sub


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-06-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Matching ZIP code with post name (VBA)

    My mistake. Should be:

    Please Login or Register  to view this content.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    i = WorksheetFunction.CountA(Range("c1:c1000"))
    u = WorksheetFunction.CountA(Range("b1:b1000"))

    If Sheets("zip").Range("b2").End(xlDown).Offset(0, 1) = "" Then _
    Sheets("zip").Range("b2").End(xlDown).Offset(0, 1).End(xlUp).AutoFill Destination:=Range("c" & i, "c" & u)

    End Sub

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-06-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Matching ZIP code with post name (VBA)

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    i = WorksheetFunction.CountA(Range("c1:c1000"))
    u = WorksheetFunction.CountA(Range("b1:b1000"))

    If Sheets("zip").Range("b2").End(xlDown).Offset(0, 1) = "" Then _
    Sheets("zip").Range("b2").End(xlDown).Offset(0, 1).End(xlUp).AutoFill Destination:=Range("c" & i, "c" & u)

    End Sub

  7. #7
    Registered User
    Join Date
    12-06-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Matching ZIP code with post name (VBA)

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)




    i = WorksheetFunction.CountA(Range("c1:c1000"))
    u = WorksheetFunction.CountA(Range("b1:b1000"))

    If Sheets("zip").Range("b2").End(xlDown).Offset(0, 1) = "" Then _
    Sheets("zip").Range("b2").End(xlDown).Offset(0, 1).End(xlUp).AutoFill Destination:=Range("c" & i, "c" & u)

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1