+ Reply to Thread
Results 1 to 13 of 13

IF Statement on multiple cells

  1. #1
    Registered User
    Join Date
    12-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    IF Statement on multiple cells

    Hi All,

    I'm after a formula that will look at a number of cells(that are not in a range) with the word "C" and if they all = "C" then I want the cell to come back with the result "yes" otherwise "no".

    Sorry sounds complicated I know!

    Thank you,
    S

  2. #2
    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 Statement on multiple cells

    Can you post a sample workbook that demonstrates what you want to see?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF Statement on multiple cells

    =if(countif(A1:A100,"=C")+countif(C4:C50,"=C")=counta(A1:A100,C4:C50),"yes","no")

    ?

  4. #4
    Registered User
    Join Date
    12-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: IF Statement on multiple cells

    Please find attached, thanks
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF Statement on multiple cells

    maybe:
    =IF(SUM(IF(ODD(COLUMN(A2:M2))=COLUMN(A2:M2),1,0)*IF(A2:M2="c",0,1)),"no","yes")
    as an array formula (confirm with ctrl+shift+enter) in N2?

  6. #6
    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 Statement on multiple cells

    Using your sample workbook, this regular formula, copied down, returns: Yes if all referenced cells equal C, otherwise: No
    Please Login or Register  to view this content.
    Is that something you can work with?

  7. #7
    Registered User
    Join Date
    12-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: IF Statement on multiple cells

    @yudlugar, thank you for your help but it didn't work :-(

    @Ron, that worked perfectly! Many thanks for your help.

    Could you please advise what the ,2 and =7 is for so I can understand the formula better for future?

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF Statement on multiple cells

    sunshine, thanks for the feedback

    did you confirm it has an array formula (control+shift+enter instead of just enter when putting the formula in?)

  9. #9
    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 Statement on multiple cells

    Sure...
    In this formula: =IF(SUMPRODUCT(MOD(COLUMN(A2:M2),2)*(A2:M2="C"))=7,"Yes","No")
    this section: MOD(COLUMN(A2:M2),2)
    returns the MOD ("leftover amount") when the column number is divided by 2.
    (Col_A is column number 1, Col_B is column number 2, Col_C is column number 3, etc)
    Odd column numbers have a mod of 1.
    Even column numbers have a mod of 0.

    So, that part returns an array of these values {1,0,1,0,1,0,1,0,1,0,1,0,1}
    which are multiplied by the test for cell values that equal "C".

    The 7 is the count of relevant cells in the referenced range (A, C, E, G, I, K, M).
    So if the count of C's is 7, then ALL of the relevant cells contain "C" and the result is Yes.

    Does that help?

  10. #10
    Registered User
    Join Date
    12-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: IF Statement on multiple cells

    @yudlugar, sorry that was silly of me, I didn't do the control+shift+enter at the end. That has worked perfectly as well, thanks very much.

    @Ron, that makes a lot more sense, thank you for the clarification.

    The problem is when using both formulas provided on the file I'm working on, it doesn't work even though I've changed the cells etc. I have now copied and pasted the data into exactly the same cells I am using on my work file on sheet 2. Could you please tell me the formula based on these cells?

    Also @yudlugar, if you don't mind, could you explain what the formula is doing as Ron has described above.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: IF Statement on multiple cells

    Hi:
    =IF(SUM(IF(ODD(COLUMN(A2:M2))=COLUMN(A2:M2),1,0)*IF(A2:M2="c",0,1)),"no","yes")


    IF(ODD(COLUMN(A2:M2))=COLUMN(A2:M2),1,0)
    is what I came up with to test if the column was an "odd" number (because every other cell had "c" in it).
    The odd function rounds the number to the nearest odd number, so if it is an even number, it will return 0, and odd number will return 1.

    Note - I didn't use ISODD() because it didn't seem to work in array formula.

    IF(A2:M2="c",0,1)
    then returns 0 if the cell has c in it or 1 if it does not.

    I'm then left with 2 arrays of numbers (one element in the array for each cell), one that is 0 for even and one that is 0 for "c" cells.

    I then multiply these arrays together, which means, that if there are any odd columns that do not contain c, they will remain as a "1". Taking the sum of this array will return 0 if all the odd columns have c in them, which is what I then test to assign no/yes.

  12. #12
    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 Statement on multiple cells

    Your new range begins in an EVEN number column...so your formula needs to reverse the MOD logic.
    Try this regular formula:
    Please Login or Register  to view this content.
    Does that help?

  13. #13
    Registered User
    Join Date
    12-07-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: IF Statement on multiple cells

    Hi Both,

    Thank you for all your help, the forumlas worked perfectly. Very much appreciated.

    Kind Regards,
    S

+ 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. IF statement multiple cells
    By daemon in forum Excel General
    Replies: 1
    Last Post: 10-24-2011, 02:27 PM
  2. if statement for multiple cells
    By Marekw in forum Excel General
    Replies: 2
    Last Post: 03-06-2011, 04:56 PM
  3. if statement for multiple cells
    By ebswd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2009, 02:05 AM
  4. If statement for multiple cells
    By rlkerr1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-01-2007, 02:02 PM
  5. if statement using multiple cells..
    By Minx1976 in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 05-17-2007, 12:29 PM

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