+ Reply to Thread
Results 1 to 14 of 14

Vlookup within an If statement

  1. #1
    Registered User
    Join Date
    12-11-2015
    Location
    Kansas
    MS-Off Ver
    2010
    Posts
    5

    Vlookup within an If statement

    I have the following If Statement
    =IF(ISNUMBER(B11),VLOOKUP(B11,Products!B3:M314,11,FALSE),"")

    What I need to do:
    if there is a # in B11 then do the Vlookup to find the product, then I want it to look in column 5 of that found product row to see if there is a #. If so, then return column 4 of that row. if not, return column 8 of that row.

    How do I do that?

    Misty

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Vlookup within an If statement

    I did this with a helper column. Your original formula should read as: =IF(ISNUMBER(B11)=TRUE,VLOOKUP(B11,Products!B3:M314,11,FALSE),"")

    Assume your formula is in cell D1, then in the helper column =IF(ISNUMBER(D1)=TRUE,VLOOKUP(B11,Products!B3:M5,4,FALSE),VLOOKUP(B11,Products!B3:M5,8,FALSE))
    Last edited by alansidman; 12-11-2015 at 01:25 PM.
    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

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    Maybe something like

    =IF(ISNUMBER(B11),IF(ISNUMBER(--(VLOOKUP(B11,Products!$B$3:$F$314,5,0)&"")),VLOOKUP(B11,Products!$B$3:$E$314,4,0),VLOOKUP(B11,Products!$B$3:$I$314,8,0)),"")

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    Quote Originally Posted by alansidman View Post
    I did this with a helper column. Your original formula should read as: =IF(ISNUMBER(B11)=TRUE,VLOOKUP(B11,Products!B3:M314,11,FALSE),"")
    That would incorrectly suggest that there is a problem with the original formula.

    ISNUMBER() already returns a Boolean value, so to test that again as you have done, i.e. IF(TRUE=TRUE, is a superfluous and pointless action.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Vlookup within an If statement

    Jason is correct. Thanks for noting that. Overthinking sometimes causes this type of senior moment.

  6. #6
    Registered User
    Join Date
    12-11-2015
    Location
    Kansas
    MS-Off Ver
    2010
    Posts
    5

    Re: Vlookup within an If statement

    that didn't work. let me try and post a pic...first worksheet.jpgsecond worksheet.jpg
    on the order sheet
    E11 is where I put your formula. it returned a 0
    In that cell I need the following returned:
    I need it to look in B11 to see the product code
    It needs to search that code on the Products worksheet (range above)
    when It finds the row (it happens to be row 134), I need it to look in column F (the 5th column)
    if there is a number in that column then it needs to return column 4 (which in this example should be GL)
    if there is not a number in that column then it needs to return column 10. (sorry miscounted earlier...)

    Jason.B when I put your code in
    =IF(ISNUMBER(B11),IF(ISNUMBER(--(VLOOKUP(B11,Products!$B$3:$F$314,5,0)&"")),VLOOKUP(B11,Products!$B$3:$E$314,4,0),VLOOKUP(B11,Products!$B$3:$I$314,8,0)),"")
    I get #REF

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    Quote Originally Posted by alansidman View Post
    Overthinking sometimes causes this type of senior moment.
    Some of us don't need to overthink to have senior moments, they just occur frequently without warning

    mistywood, could you attach a sample spreadsheet to your post instead of screen captures, that way we don't have to spend hours retyping your data to test before we suggest.
    Last edited by jason.b75; 12-11-2015 at 01:32 PM.

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    How do you relate the data in your first screen cap to row 134 of the second screen cap?

    I can't see anything that matches those 2 records.

    Formula shouldn't return #REF unless you made any changes to it, as I said in my previous post, it's easier and more accurate for us to work with a real spreadsheet than a screen cap.
    Last edited by jason.b75; 12-11-2015 at 01:45 PM.

  9. #9
    Registered User
    Join Date
    12-11-2015
    Location
    Kansas
    MS-Off Ver
    2010
    Posts
    5

    Re: Vlookup within an If statement

    how do I attach a file

  10. #10
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    Click on GO ADVANCED and use the paperclip icon to open the upload window. The picture linked below shows where to find it.

    View Pic

  11. #11
    Registered User
    Join Date
    12-11-2015
    Location
    Kansas
    MS-Off Ver
    2010
    Posts
    5

    Re: Vlookup within an If statement

    ok here is the attachment. hope it helps.
    Order Sheet example.xlsm

  12. #12
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    The formula broke because you change 8 to 10 but didn't expand the range, so it was looking for a column that didn't exist.

    See if this gives the expected results.

    =IF(ISNUMBER(B11),IF(ISNUMBER(--(VLOOKUP(B11,Products!$B$3:$F$4,5,0)&"")),VLOOKUP(B11,Products!$B$3:$E$4,4,0),VLOOKUP(B11,Products!$B$3:$K$4,10,0)),"")

  13. #13
    Registered User
    Join Date
    12-11-2015
    Location
    Kansas
    MS-Off Ver
    2010
    Posts
    5

    Re: Vlookup within an If statement

    that works perfect!!! Thank you!!

  14. #14
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Vlookup within an If statement

    An alternative method that also works with your sample data.

    Just to point out that there is nothing wrong with the last one, it just looks wrong to me because it is long and repetitive. This one is more concise, although probably harder to understand.

    =IFERROR(LEFT(LOOKUP("y",VLOOKUP(B11,Products!$B$3:$K$4,{10,4},0)&"z"),2),"")

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Vlookup IF Statement
    By N.Lamech in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-12-2014, 12:24 PM
  2. Help with Vlookup and IF statement please
    By gvishnu in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-25-2013, 12:54 PM
  3. VLOOKUP vs IF statement?
    By jakeisbill in forum Excel General
    Replies: 3
    Last Post: 07-03-2012, 09:45 PM
  4. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  5. Using a VLOOKUP and IF statement inside an IF statement
    By Isis3 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-08-2011, 07:04 PM
  6. [SOLVED] IF Statement with VLOOKUP
    By berger01 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-27-2011, 10:21 AM
  7. Vlookup with if statement
    By Traymond in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-24-2010, 02:09 PM
  8. Vlookup & If statement
    By broadspectrum in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2006, 02:11 AM

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