+ Reply to Thread
Results 1 to 8 of 8

Replacing IF with CHOOSE

  1. #1
    Forum Contributor
    Join Date
    10-10-2006
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2019, Win 10
    Posts
    102

    Replacing IF with CHOOSE

    Ex. 2000
    XP Pro SP3

    Is there a way to replace nested IFs with the CHOOSE function so that I can overcome the seven nested IFs barrier in 2000?

    I can replace IF with CHOOSE in a single IF formula which works, but I cannot see how to use 'nested' CHOOSE (if it is at all possible).



    TIA

    Zagra147
    Last edited by Zagra147; 12-29-2010 at 05:00 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Replacing IF with CHOOSE

    I think you need to give us an example of what you mean
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    10-10-2006
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2019, Win 10
    Posts
    102

    Re: Replacing IF with CHOOSE

    This formula extracts data such as description, supplier, nutrition from an Excel database to compile daily food intake. A simple arbtrary code is input into A1 prefixed by the appropriate letter to access the correct sheet in the database.
    IF(LEFT($A1,1)="A",VLOOKUP($A1,[Food_List_2011.xls]Alcohol!$B$1:$N$100,2,FALSE),IF(LEFT($A1,1)="F",VLOOKUP($A1,[Food_List_2011.xls]Foods!$B$1:$N$100,2,FALSE))) etc.

    I wish to add more sheets, 'snacks', 'meals', etc. which would exceed the limit for nested IFs.

    This works:
    CHOOSE(LEFT($A1,1)="A",VLOOKUP($A1,[Food_List_2011.xls]Alcohol!$B$1:$N$100,2,FALSE)

    But this doesn't:
    CHOOSE(LEFT($A1,1)="A",VLOOKUP($A1,[Food_List_2011.xls]Alcohol!$B$1:$N$100,2,FALSE),CHOOSE(LEFT($A1,1)="F",VLOOKUP($A1,[Food_List_2011.xls]Foods!$B$1:$N$100,2,FALSE)))
    Last edited by Zagra147; 12-22-2010 at 02:08 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Replacing IF with CHOOSE

    Perhaps ...

    =VLOOKUP($A1, CHOOSE(MATCH(LEFT(A1), {"A","F","D"}, 0), Alcohol!$B$1:$N$100, Foods!$B$1:$N$100, Desserts!$B$1:$N$100), 2, FALSE)
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Replacing IF with CHOOSE

    Something like this:

    =VLOOKUP($A1,CHOOSE(MATCH(LEFT($A1,1),{"A","F"},0),[Food_List_2011.xls]Alcohol!$B$1:$N$100,[Food_List_2011.xls]Foods!$B$1:$N$100),2,FALSE)

    listing all the possibilities in the second part of the Match function and the corresponding vlookup ranges as the choice items...
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  6. #6
    Forum Contributor
    Join Date
    10-10-2006
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2019, Win 10
    Posts
    102

    Re: Replacing IF with CHOOSE

    Thankyou shg & NVBC. That works fine with text strings - brilliant!
    But, if I use your suggestions to access numerical data with a multiplier at the end of the formula to calculate quantities, e.g. (formula)*B1 - which is the portion size cell, then if 'A1' (the code cell) is blank, I get '#VALUE!' instead of a blank cell.
    I have tried:
    =IF(A1="","",(formula)*B1
    with no success. Any suggestions?

    Again

    TIA

    Zagra147

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Replacing IF with CHOOSE

    Is that A1 the same A1 as in your Vlookup?

    i.e

    you have... =IF(A1="","",VLOOKUP(A1,.....)*B1) ?

    If so, then it should return a blank if A1 is blank... and if the Vlookup returns a numerical result then you should get a numerical result.

    Note that the multiplier needs to be associated only with the Vlookup() part.. so it should follow immediately after the closing parenthesis of the Vlookup() function and just before the final closing parenthis of the formula.

  8. #8
    Forum Contributor
    Join Date
    10-10-2006
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2019, Win 10
    Posts
    102

    Re: Replacing IF with CHOOSE

    NBVC
    That is correct.
    This what I have:
    =IF($A1="","",VLOOKUP($A1,CHOOSE(MATCH(LEFT($A1,1),{"A","F","M","R"},0),[Food_List_2011.xls]Alcohol!$D$9:$N$1150,[Food_List_2011.xls]Foods!$D$6:$O$1150,Food_List_2011.xls]Meals!$D$6:$O$1150,Food_List_2011.xls]RPSM!$D$6:$O$1150),4,FALSE)))*$B1/100.

    That should work.

    Ah. Just had a thought... It's a parenthesis problem:

    =IF($A1="","",(VLOOKUP($A1,CHOOSE(MATCH(LEFT($A1,1),{"A","F","M","R"},0),[Food_List_2011.xls]Alcohol!$D$9:$N$1150,[Food_List_2011.xls]Foods!$D$6:$O$1150,[Food_List_2011.xls]Meals!$D$6:$O$1150,[Food_List_2011.xls]RPSM!$D$6:$O$1150),4,FALSE)))*$B1/100).

    The whole vlookup including including the multiplier must be enclosed within ().

    This now works ok.

    Many thanks

    Zagra147

+ 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