+ Reply to Thread
Results 1 to 9 of 9

IF COUNTIF Help

  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    michigan
    MS-Off Ver
    Excel 2003
    Posts
    3

    IF COUNTIF Help

    I'm trying to insert a IF/COUNTIF function to look at a range of cells and print either "UNSTABLE" or "OK". If within the range of cells are values of all 'water' or all 'oil', I want the function to say "OK". If there is any mixture of water and oil, I want the function to say "UNSTABLE". I think the problem with my function below is in the AND statement, as no matter what values are in the A:1:A4 range, the function says "OK". Does anyone know a way to fix this function, or suggest a different function to use?


    A1 = water
    A2 = water
    A3 = oil
    A4 = water

    =IF(COUNTIF(A1:A4, AND("water","oil" )), "UNSTABLE","OK")

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: IF COUNTIF Help

    Try..

    =IF(COUNTIF(A1:A4,A1)=COUNTA(A1:A4),"OK","UNSTABLE")
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: IF COUNTIF Help

    Try

    =IF(OR(COUNTIF(A1:A4,"water")=4,COUNTIF(A1:A4,"oil")=4),"ok","unstable")
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

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

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  4. #4
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: IF COUNTIF Help

    Two things:

    1) You're missing a bit of syntax in your condition in your if statement. It will always be true, but will not always be >1...
    2) AND means that both must be true... and I don't think it works in a countif like that.
    =IF(OR(COUNTA(A1:A4)=COUNTIF(A1:A4,"Water"),COUNTA(A1:A4)=COUNTIF(A1:A4,"Oil")),"Ok","Unstable")
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  5. #5
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: IF COUNTIF Help

    I love how we all gave 3 different answers..

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: IF COUNTIF Help

    This is Excel!!!!

  7. #7
    Registered User
    Join Date
    11-09-2012
    Location
    michigan
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: IF COUNTIF Help

    Awesome. Both suggestions work! Thanks for the help. Here's a follow up question: What if I want to add different values to A1:A4 range, but I still only want the function to say "UNSTABLE" if water and oil are in the data range together. For example,

    A1 = water
    A2 = water
    A3 = emulsion
    A4 = water

    The function will say "UNSTABLE" even though oil and water are both not present.

  8. #8
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: IF COUNTIF Help

    Try..

    =IF(AND(COUNTIF(A1:A4,"Water")>0,COUNTIF(A1:A4,"Oil")>0),"Unstable","OK")

  9. #9
    Registered User
    Join Date
    11-09-2012
    Location
    michigan
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: IF COUNTIF Help

    Perfect! Thanks ACE!

+ 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