+ Reply to Thread
Results 1 to 8 of 8

LOOKUP Gives Wrong Value?

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2007
    Posts
    4

    LOOKUP Gives Wrong Value?

    Hello,

    I'm using LOOKUP to do something simple, but it appears to be giving a wrong (or I should say, at least unexpected) result some of the time.

    I have a simple table where row 1 has four names in cols A through D (say "First", "Second", "Third", and "Fourth"). In rows 2 through 16, I have placed an "X" in one or more of the cells in each row. I followed a binary pattern to account for all combinations of X. For example row 2 has blank,blank,blank,X. Row 12 has X,blank,X,X. Row 16 has X,X,X,X.

    In col E, for each row 2 through 16, I have the following formula:

    =LOOKUP("X",A2:D2,$A$1:$D$1)

    Every row in col E gives me the right answer except for two:
    row 6 (blank,X,blank,X) gives me "Second" where I expected "Fourth".
    row 14 (X,X,blank,X) gives me "Second" where I expected "Fourth".

    I don't understand this as there are other rows with blanks in col C, yet it returns what I expect. For example:
    row 10 (X,blank,blank,X) gives the expected value of "Fourth".

    I tried this with MATCH too, and those same two locations give me the same unexpected index.

    Can someone please explain this? I just want to get the col value in the first row that corresponds to the last "X" in each row.

    Thanks, and sorry this description is so long. Harder to explain than to just look at!
    Tony
    Attached Images Attached Images

  2. #2
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.92 (24120731))
    Posts
    9,111

    Re: LOOKUP Gives Wrong Value?

    lookup - needs to be sorted in ascending order to give the correct result - is that the issue at all

  3. #3
    Registered User
    Join Date
    03-25-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: LOOKUP Gives Wrong Value?

    I don't really know. How is an empty cell sorted as compared to a cell with "X" in it?

    Why would (X, blank, blank, X) work but not (X, X, blank, X)?

  4. #4
    Registered User
    Join Date
    03-07-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: LOOKUP Gives Wrong Value?

    This is really strange, but it has to have something to do with the spacing. It's giving you the right-most x when there are two consecutive x's and then a space. So, x-x-blank-x is second, but x-blank-x-x is fourth. I added a fifth row to check and it's doing the same thing, but on the third consecutive x. So, x-x-blank-x-x is correctly giving me fifth, but x-x-x-blank-x is giving me third. It stops looking once it hits that space.

  5. #5
    Registered User
    Join Date
    03-25-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: LOOKUP Gives Wrong Value?

    I know, right? It also works when you have two blanks in a row, like x-blank-blank-x gives Fourth!

  6. #6
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: LOOKUP Gives Wrong Value?

    Hi soloProgrammer

    Try the following :
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  7. #7
    Registered User
    Join Date
    03-25-2013
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: LOOKUP Gives Wrong Value?

    Hey now Kevin, that worked! Thank you!

    But why does that work?

  8. #8
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: LOOKUP Gives Wrong Value?

    Hi soloProgrammer

    The function is looking up "zzz" but it can't find it so it returns the last listed value.
    Thanks for the feed back.

+ 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