+ Reply to Thread
Results 1 to 10 of 10

Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    I have the code below. I am having difficulty on figuring out how to code VBA to trigger a 2nd vlookup (or match, something) if there are multiple results for the initial vlookup(). Which as I am typing this I am realizing that I need to use a different function as vlookup only retrieves the first match.


    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    Try this...

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 11-14-2012 at 02:09 PM.

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    Alas, the code did not work correctly. It returns "IL01" no matter what the geozip is.
    I am playing with the following code (as well as moving the GEOZIP to Col B from Col D) to setup a range for a 2nd vlookup

    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    Quote Originally Posted by lloydgodin View Post
    Alas, the code did not work correctly. It returns "IL01" no matter what the geozip is.
    I am playing with the following code (as well as moving the GEOZIP to Col B from Col D) to setup a range for a 2nd vlookup
    It worked for me using your example File.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,719

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    Look at this thread, as I just posted a UDF for multi-vlookups

    http://www.excelforum.com/excel-form...cate-data.html

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    I downloaded the example file and used your code. It still is returning IL01 every time.
    Oh yea, that's because my example is bad. It's IL01 for both zipcodes for (forest park)... I'm a fktard.
    Let me check with another city....

  7. #7
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    It's working!!!

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    Alternatively, you could have a column on the Data sheet that is a City&GeoZip combo e.g.
    GLENVIEW622

    Then do a VLOOKUP on that column and look for the City&Geozip combo.

  9. #9
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    OK so it's not working correctly.

    For example, if I enter WAUKEGAN as the city and the patient zipcode as 60085 I am getting the "Zipcode is not found in IL" message.

    Please Login or Register  to view this content.
    should only be used if the patient city has 2+ results.

    I uploaded a new file with the complete dataset.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: Multiple Matches Coding Problem [Excel 2010/14, VBA Only]

    Changed the code as follows. It works. Not sure what potential errors may/may not occur...

    Please Login or Register  to view this content.

+ 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