+ Reply to Thread
Results 1 to 10 of 10

IF with 3 variables

  1. #1
    Registered User
    Join Date
    05-18-2010
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    54

    IF with 3 variables

    Hi guys,

    I think it is an easy problem for you.
    Please find below the cells. I want to create a formula in D that tells me the type of data we are working on based on value in column a,b and c.
    The logic for d2 should be
    "if a2 is Y and b2 and c2 are N then give me apple" and
    "if b2 is Y and a2 and c2 are N then give me banana" and
    "if c2 is Y and b2 and a2 are N then give me pear"

    there is can be only a "Y" per raw.

    a b c d
    1 Apple Banana Pear Type
    2 Y N N Apple
    3 N Y N Banana
    4 N N Y Pear

    Thanks in advance for your help.
    Regards,
    Last edited by TRS; 01-11-2011 at 12:05 PM.

  2. #2
    Registered User
    Join Date
    05-18-2010
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: IF with 3 variables

    I attached a printscreen. It is clearer.
    Attached Images Attached Images

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: IF with 3 variables

    Maybe:

    =IF(COUNTIF(A2:C2,"Y")>1,"Too Many Y's",IF(A2="Y","apple",IF(B2="Y","banana",IF(C2="Y","pear",""))))

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

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

    Re: IF with 3 variables

    Try:

    =INDEX({"Pear","Banana","Apple"},MATCH(A2&B2&C2,{"NNY","NYN","YNN"},0))
    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.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: IF with 3 variables

    If you are only interested in the position of the "Y",
    here are some options:

    Please Login or Register  to view this content.
    or...for more flexibility, read the column headings based on the matched "Y":
    Please Login or Register  to view this content.
    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  6. #6
    Valued Forum Contributor scottylad2's Avatar
    Join Date
    09-03-2010
    Location
    edinburgh
    MS-Off Ver
    Office 2007 Prof & Office 2010 Student Edition
    Posts
    629

    Re: IF with 3 variables

    IF(AND(A2="y",B2="n",C2="n"),"apple",IF(AND(B2="y",A2="n",C2="n"),"banana",IF(AND(C2="y",B2="n",A2="n"),"pears","")))

    think that covers all scenarios, including a non mentioned combination. ie 2 y's anywhere will display as blank
    Windows 7 using Office 2007 & 2010

    Remember your [ code ] [ /code ] tags, makes reading soooo much easier

  7. #7
    Registered User
    Join Date
    05-18-2010
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: IF with 3 variables

    Thank you all guys!

    I used =INDEX({"Pear","Banana","Apple"},MATCH(A2&B2&C2,{"NNY","NYN","YNN"},0)) as it was the first one working

    instead =IF(COUNTIF(A2:C2,"Y")>1,"Too Many Y's",IF(A2="Y","apple",IF(B2="Y","banana",IF(C2="Y","pear","")))) did not work! maybe I made a mistake.
    Anyway Thanks again!

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: IF with 3 variables

    And another way
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by Marcol; 01-11-2011 at 12:38 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: IF with 3 variables

    Quote Originally Posted by TRS View Post
    I used =INDEX({"Pear","Banana","Apple"},MATCH(A2&B2&C2,{"NNY","NYN","YNN"},0)) as it was the first one working

    instead =IF(COUNTIF(A2:C2,"Y")>1,"Too Many Y's",IF(A2="Y","apple",IF(B2="Y","banana",IF(C2="Y","pear","")))) did not work! maybe I made a mistake.
    NBVC's is a 'nicer' solution but mine should work fine.

    Dom

  10. #10
    Registered User
    Join Date
    05-18-2010
    Location
    Europe
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: IF with 3 variables

    For sure I made a mistake! Thank you Dom!

+ 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