+ Reply to Thread
Results 1 to 9 of 9

Match one out of several possibilities

Hybrid View

  1. #1
    Registered User
    Join Date
    07-15-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Match one out of several possibilities

    Hello,
    I'm looking for a formula that will return a zip code when looking up a county. Obviously, counties may have several zip codes within them, but I would like Excel to pick one randomly and match it to the county that it's in. I have a table with all zip codes and their associated counties.
    Then I have an other table with people and the counties they live in. I want to match any zip code to them (regardless of what it truly is) that is in that county...
    Thank you!
    Caroline
    Last edited by carojvi; 07-18-2011 at 09:52 AM.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Match one out of several possibilities

    Hi Caroline and welcome to the forum.

    To do this in a single formula, you can use an array formula such as this:
    =INDEX($B$2:$B$19,
        LARGE(IF($A$2:$A$19=$H2,ROW($A$2:$A$19)-ROW($A$2)+1),
            RANDBETWEEN(1,COUNTIF($A$2:$A$19,$H2))))
    It will return a #NUM! error if the country is not in the lookup table.
    Attached Files Attached Files
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    07-15-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Match one out of several possibilities

    Hi Colin,
    Thank you so much for the example. The formula seems to be working but doesn't return a zip everytime. Most of the results are #num but when I hit F9, sometimes I do get a result. How can I get Excel to return something in each cell?
    I'm going to try attaching the file for you to see.
    Thank you!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    07-15-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Match one out of several possibilities

    I had a ref problem, but even when I fixed it, it still doesn't work the way I want...

  5. #5
    Registered User
    Join Date
    07-15-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Match one out of several possibilities

    Sorry, I'm working on this... I took out the 'large' part of the formula and it seems to be working perfectly now Thank you again!!

  6. #6
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Match one out of several possibilities

    Hi Caroline,

    The LARGE() part is required. The reason it isn't working the way you wanted is because you hadn't entered it as an array formula. If you look at my attached example, you'll notice that the formulas in the formula bar are surrounded by parentheses { }. To get this effect, when you type the formula into the formula bar, to complete the entry, instead of just pressing the usual ENTER, you have to press CTRL+SHIFT+ENTER. Note that you can't enter the { } manually yourself - you have to let Excel do it for you.

    I've attached your file with corrections. Yes, the formulae take a long time to calculate because you have 40,000+ rows of data.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-15-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Red face Re: Match one out of several possibilities

    Thank you... I will re-add... should have spot checked, it doesn't work indeed if I take out the large, it only 'seems' to be working. Bugger...

  8. #8
    Registered User
    Join Date
    07-15-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Match one out of several possibilities

    OK, I'm all set. Is there somewhere I can click to mark this question as solved, give you kuddos, etc?

  9. #9
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Match one out of several possibilities

    Hi Caroline,

    To mark your thread as solved, please click EDIT in your first post, click GO ADVANCED and set the PREFIX box to SOLVED.

    You can tap on the scales in the top right corner of a member's post to give that member some kudos.

    Thanks

+ 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