+ Reply to Thread
Results 1 to 10 of 10

Nested IFs AND/OR Dilemma

  1. #1
    Registered User
    Join Date
    03-16-2022
    Location
    USA
    MS-Off Ver
    365 ProPlus
    Posts
    3

    Post Nested IFs AND/OR Dilemma

    I have a spreadsheet with a lot of different options for text and I need to analyze a cell and return a numeric value. I've tried nested IFs but that doesn't seem to work with text so I'm kind of stuck. Any help is greatly appreciated.

    EXAMPLE:

    Cell A1 could contain "None", "Non-sterile", "EO", "R", or "Temp"

    I want to return a number into a different cell depending on what is in the first cell i.e. if "None" enter 0, if "Non-sterile" enter 1, if "EO" enter 2, if "R" enter 3, or if "Temp" enter 4.

    This particular example has the most options. I have a lot of cells that are a simple IF X than 0, IF Y then 1 and those equations are working just fine. I just can't figure out how to return a value dependent on what text is in the cell. Do I need to make a table with these options and do a LOOKUP instead? If so, what's the best way to go about doing that as I've never used the LOOKUP function, I only know it exists.

    TIA!
    Pooch

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Nested IFs AND/OR Dilemma

    Hi there.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 non-editable pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet complete with an explanation and some expected results.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

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

    Re: Nested IFs AND/OR Dilemma

    =if(A1="None",0,if(A1="Non-sterile",1,if(A1="EO",2,if(A1="R", 3,if(A1="Temp",4,"")))))
    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

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Nested IFs AND/OR Dilemma

    Welcome to the forum.

    Try this:

    =LOOKUP(SUBSTITUTE(A1,"-",""),{"EO","None","Nonsterile","R","Temp"},{2,0,1,3,4})
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,147

    Re: Nested IFs AND/OR Dilemma

    Try

    =LOOKUP(A1,{"EO","None","Non-sterile","R","Temp"},{2,0,1,3,4}

    The LOOKUP values have to be in ascending order (numeric or text)
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  6. #6
    Registered User
    Join Date
    03-16-2022
    Location
    USA
    MS-Off Ver
    365 ProPlus
    Posts
    3

    Re: Nested IFs AND/OR Dilemma

    Thanks for the help everyone! You are Excel saviors! I would have tried to post an example but since I wasn't even sure which route to take to get the desired outcome it wouldn't have helped much.

    I did originally try that nested IFs equation and had it written just like that but for some reason it wasn't giving me the right values. The LOOKUP(SUBSTITUTE solved this problem though. Thanks again everyone, you're all great!

  7. #7
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Nested IFs AND/OR Dilemma

    I prefer VLOOKUP for this kind of thing as then typos return errors rather than matching the wrong answer, e.g.

    =VLOOKUP(A1,{"None",0;"Non-sterile",1;"EO",2;"R",3;"Temp",4},2,0)

    I find it easier to input this way as well as it doesn't need to be in a particular order and the lookup value is entered next to the key. Though personally I would have the lookup range someone in the workbook in 99% of cases.

  8. #8
    Registered User
    Join Date
    03-16-2022
    Location
    USA
    MS-Off Ver
    365 ProPlus
    Posts
    3

    Re: Nested IFs AND/OR Dilemma

    Quote Originally Posted by nick.williams View Post
    I prefer VLOOKUP for this kind of thing as then typos return errors rather than matching the wrong answer, e.g.

    =VLOOKUP(A1,{"None",0;"Non-sterile",1;"EO",2;"R",3;"Temp",4},2,0)

    I find it easier to input this way as well as it doesn't need to be in a particular order and the lookup value is entered next to the key. Though personally I would have the lookup range someone in the workbook in 99% of cases.
    What are the 2 & 0 referring to at the end of that equation?

  9. #9
    Valued Forum Contributor
    Join Date
    07-23-2013
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    988

    Re: Nested IFs AND/OR Dilemma

    VLOOKUP looks up a value in the left-most column of an array of data, and returns the value in the specified column. The 2 refers to the 2nd column.

    The 0 is what I am in the habit of using instead of FALSE (Excel treats them the same and I type it a lot). This means it searches for an exact match, rather than an approximate match if 1 or TRUE is used.

    Hope that helps,

    Nick

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Nested IFs AND/OR Dilemma

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

+ 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. SUM Dilemma
    By Barrera006 in forum Excel General
    Replies: 3
    Last Post: 01-16-2017, 04:00 PM
  2. IF AND dilemma
    By herschen in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-11-2015, 03:47 PM
  3. [SOLVED] Capacity dilemma
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-10-2012, 11:51 AM
  4. [SOLVED] Formula dilemma!
    By Cat A in forum Excel General
    Replies: 4
    Last Post: 04-01-2012, 10:14 AM
  5. [SOLVED] Nth power dilemma
    By Andre Croteau in forum Excel General
    Replies: 6
    Last Post: 06-23-2006, 04:15 PM
  6. [SOLVED] Do Until Loop Dilemma
    By mellowe in forum Excel General
    Replies: 2
    Last Post: 04-17-2006, 12:45 PM
  7. Auto_open Dilemma -- Help
    By Chuckles123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2005, 11:01 PM

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.6.0 RC 1