+ Reply to Thread
Results 1 to 14 of 14

Thread: Two Vlookups do not work with IF. Why?

  1. #1
    Registered User
    Join Date
    01-24-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Two Vlookups do not work with IF. Why?

    Hi,

    quite a newbie here. I've got the following if formula with two vlookups however it does not work for probably obvious reasons.

    =IF(VLOOKUP(A1;[Input.xls]Sheet1!$A$1:$B$5;2;0)=”OK”;”OK”;VLOOKUP(A1;[Input.xls]Sheet2!$A$1:$B$5;2;0))

    This simple logic doesn't work as I see.

    I suspect I need some sort of nested If or smht...

    Can anyone give a quick help with this?

    'files attached..

    thanks in advance,
    /andy.
    Attached Files Attached Files
    Last edited by andy.smith; 01-25-2012 at 03:07 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-03-2009
    Location
    Firenze, Italy
    MS-Off Ver
    Excel 2000 XP
    Posts
    436

    Re: Two Vlookups do not work with IF. Why?

    Hi Andy,

    what do need to obtain from the formula if there is not a correspondence between the two lists?

    Regards
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon below the post.

    Please, mark your thread [SOLVED] if you received your answer.

    Forum rules: http://www.excelforum.com/forum-rule...rum-rules.html

  3. #3
    Registered User
    Join Date
    09-10-2011
    Location
    INDIA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Two Vlookups do not work with IF. Why?

    The formula used is correct. Problem is 6666 is actually not available in the input sheet.try for 5555 or 4444. It will work .

  4. #4
    Registered User
    Join Date
    01-24-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Two Vlookups do not work with IF. Why?

    Thanks guys for looking into this.

    Canapone, the attached are dummy sheets, since the originals contain some sensitive info. What i'm trying to achieve is that vlookup would check Input file>sheet1, say B1 if it contains "OK", if it does, retrieves "OK", if it does not, another vlookup should retrieve another value from Input file>sheet2.

    The result should be in the Output file.

    for some reason it only retrieves the result from the first vlookup, the if false condition vlookup does not work.

    nadarajan, the 6666 is actually in the sheet2, the same Input file. But the formula does not work even if both sets of data are inthe same sheet/workbook.

    any insights welcome.
    /andy

  5. #5
    Valued Forum Contributor
    Join Date
    12-03-2009
    Location
    Firenze, Italy
    MS-Off Ver
    Excel 2000 XP
    Posts
    436

    Re: Two Vlookups do not work with IF. Why?

    Hi,

    sure: I did not have read the formula correctly.

    A possible solution:

    =IF(not(iserror(VLOOKUP(A1;[Input.xls]Sheet1!$A$1:$B$5;2;0)=”OK”));”OK”;VLOOKUP(A1;[Input.xls]Sheet2!$A$1:$B$5;2;0))
    Regards
    Last edited by CANAPONE; 01-24-2012 at 09:05 AM.
    -----------------------------------------------------

    At Excelforum, you can say "Thank you!" by clicking the star icon below the post.

    Please, mark your thread [SOLVED] if you received your answer.

    Forum rules: http://www.excelforum.com/forum-rule...rum-rules.html

  6. #6
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Two Vlookups do not work with IF. Why?

    Quote Originally Posted by andy.smith View Post
    if it contains "OK", if it does, retrieves "OK", if it does not, another vlookup should retrieve another value from Input file>sheet2.
    What other value?
    Good luck.

  7. #7
    Registered User
    Join Date
    01-24-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Two Vlookups do not work with IF. Why?

    Canapone, the code does not work for me, sorry. Is it something to do with me using excel 2002? It says formula contains an error and highlightes "OK".

    OnErrorGoto0, the other value in sheet2 will be "OK" as well or blank. The purpose of this is that data from sheet1 would not loose it's "OK" status when moved to sheet2. And it needs actively check if it is still "OK", hence there is a need for a second vlookup to constantly retrieve the value of the particular cell.
    I hope that makes sence..

    p.s. the value for the first vlookup can be "OK" or blank

    /andy.

  8. #8
    Registered User
    Join Date
    09-10-2011
    Location
    INDIA
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Two Vlookups do not work with IF. Why?

    Sorry, I have not noticed the sheet2, Use this formula.
    =IF(ISERROR(VLOOKUP(A6,[Input.xls]Sheet1!$A$1:$B$5,2,0)),VLOOKUP(A6,[Input.xls]Sheet2!$A$1:$B$5,2,0),VLOOKUP(A6,[Input.xls]Sheet1!$A$1:$B$5,2,0))
    This will work I think

  9. #9
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Two Vlookups do not work with IF. Why?

    What do you want to return if the value is not found in either sheet? Or is #N/A acceptable? If so, nadarajan's formula should suffice.
    Good luck.

  10. #10
    Registered User
    Join Date
    01-24-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Two Vlookups do not work with IF. Why?

    Canapone, the code does not work for me, sorry. Is it something to do with me using excel 2002? It says formula contains an error and highlightes "OK".

    OnErrorGoto0, the other value in sheet2 will be "OK" as well or blank. The purpose of this is that data from sheet1 would not loose it's "OK" status when moved to sheet2. And it needs actively check if it is still "OK", hence there is a need for a second vlookup to constantly retrieve the value of the particular cell.
    I hope that makes sence..

    p.s. the value for the first vlookup can be "OK" or blank

    /andy.

  11. #11
    Registered User
    Join Date
    01-19-2012
    Location
    Delhi
    MS-Off Ver
    Excel 2003
    Posts
    10

    Talking Re: Two Vlookups do not work with IF. Why?

    =IF(ISERROR(VLOOKUP(A1,Sheet2!$A$1:$B$5,2,FALSE)),VLOOKUP(A1,Sheet1!$A$1:$B$5,2,FALSE),VLOOKUP(A1,Sh eet2!$A$1:$B$5,2,FALSE))
    Last edited by chetanmehra1989; 01-24-2012 at 10:56 AM. Reason: issue

  12. #12
    Registered User
    Join Date
    01-24-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Two Vlookups do not work with IF. Why?

    the suggested formulas arn't working fully..

    nadarajan, for some reason only sheet1 retrieves OK, while from sheet2 it retrieves "0". any ideas how to fix it?
    NA for blanks is ok for me.

    thanks for your patience with this.

    /andy.
    Last edited by andy.smith; 01-24-2012 at 01:52 PM.

  13. #13
    Valued Forum Contributor OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,647

    Re: Two Vlookups do not work with IF. Why?

    I think you will require something like this

    =LOOKUP(REPT("Z",255),CHOOSE({1,2},VLOOKUP(A6,[Input.xls]Sheet1!$A$1:$B$5,2,FALSE),VLOOKUP(A6,[Input.xls]Sheet2!$A$1:$B$5,2,FALSE)))

    which will return either 'OK' or N/A assuming the lookup cells are either blank or OK.
    Good luck.

  14. #14
    Registered User
    Join Date
    01-24-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Two Vlookups do not work with IF. Why?

    OnErrorGoto0, this is brilliant! Worked like a charm. Thanks everyone for your time and efforts.

    /andy.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0