+ Reply to Thread
Results 1 to 16 of 16

Countif and Countifs

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Chesapeake VA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Countif and Countifs

    I am having difficulty with a table in Excel 2007. For each line on the table I want a total of the number of times the letter c appears. However, I only want to check certain cells that are not adjacent to each other. So I can't put a range of cells in the formula to check. I can't use the regular Countif(s) syntax because it does not understand the seperation of the inputs by the commas. I have tried numerous different formulas with every symbol I can think of to no avail. So how do use this count formula when the cells you want the formula to look at are individual seperated cells and not ranges of cells?

    Thanks!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Countif and Countifs

    Please upload a workbook so that we can see your request in context. That would be so much easier.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-14-2013
    Location
    Chesapeake VA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Countif and Countifs

    I will try.
    The sample workbook has two lines of a medical clinic's providers schedules. The last 3 columns are the ones I want to use the formula in. In the 1st or "AM" column there I want to see the number of times the letter c appears in the "AM" column for each provider. For example, in cell AA3, I want to see how many times the "C" appears in cells C3,F3,I3,L3,O3,R3,U3, AND X3. In cell AB3, I want to see how many times the "C" appears in cells D3,G3,J3,M3,P3,S3,V3, AND Y3, etc.

    I hope I have explained this well enough and that I attached the workbook correctly.

    Brian
    Attached Files Attached Files

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,408

    Re: Countif and Countifs

    Put this formula in cell AA3:

    Formula: copy to clipboard
    =COUNTIFS($C$2:$Z$2,AA$2,$C3:$Z3,"C")


    then copy it into AB3:AC3, then copy AA3:AC3 down as far as you need to.

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    01-14-2013
    Location
    Chesapeake VA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Countif and Countifs

    Here's what I did that seemed to work:
    In Cell AA I put your recommended formula =COUNTIFS($C$2:$Z$2,AA$2,$C3:$Z3,"C") However, if I copied that same formula into AB it did not work, so I changed cell AB to =COUNTIFS($C$2:$Z$2,AB$2,$C3:$Z3,"C") and AC to =COUNTIFS($C$2:$Z$2,AC$2,$C3:$Z3,"C"). This seemd to work, even after I pasted those three formulas into the next line.

    If I could ask one more thing... If I wanted to do the exact same thing but count up the sum of all "C", "P", and "NICU" cells, what would the formulas be?

    BTW, if the people who responded ever have the time and patience I would love to have an English translation of what the symbology of these formulas actually means!

    Thanks again!

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: Countif and Countifs

    Quote Originally Posted by alexfamily5 View Post
    ... If I wanted to do the exact same thing but count up the sum of all "C", "P", and "NICU" cells, what would the formulas be?
    Try this version

    =SUM(COUNTIFS($C$2:$Z$2,AA$2,$C3:$Z3,{"C","P","NICU"}))
    Audere est facere

  7. #7
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

    Re: Countif and Countifs

    AA3: =COUNTIFS($C$2:$Z$2,AA$2,$C3:$Z3,"C")

    copy across and down

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: Countif and Countifs

    What results did you get? What did you expect?

    When I put that formula in your sample file in row 3 it gave me the result 4 - it's counting all the AM columns which contain either "C", "P" or "NICU" which means it counts cells C3, I3, R3 and U3 (3 "C"s and 1 "P"), isn't that correct?

  9. #9
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: Countif and Countifs

    I think my previous suggestion works, amended to include "D" and "N" but not "NICU", try this version in AA3 copied across and down

    =SUM(COUNTIFS($C$2:$Z$2,AA$2,$C3:$Z3,{"C","D","P","N"}))

  10. #10
    Registered User
    Join Date
    01-14-2013
    Location
    Chesapeake VA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Countif and Countifs

    Wow, that was fast! It looks to be all correct except any line that has "NICU", because it counts that too. I think in "countif" it will count a cell if the letter is anywhere in the cell, and that one has both N and C, so it is counting that cell.

  11. #11
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: Countif and Countifs

    Quote Originally Posted by alexfamily5 View Post
    I think in "countif" it will count a cell if the letter is anywhere in the cell, and that one has both N and C, so it is counting that cell.
    No, the formula I suggested doesn't count "NICU" - it will only count cells that contain exactly "C", "D", "N" or "P" (upper or lower case) - I get 3 as the PM result for Mon - that counts the "D" in G4 and the "C"s in M4 and S4

  12. #12
    Registered User
    Join Date
    01-14-2013
    Location
    Chesapeake VA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Countif and Countifs

    I tried it again, and for some reason there are 3 lines where the AM numbers are not correct. I attached the workbook with the formula answers as well as the correct answers. maybe you can figure what I am doing wrong.
    Attached Files Attached Files

  13. #13
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: Countif and Countifs

    Some of your values in column U have "trailing spaces" - a "C" followed by a space, so that isn't counted. Get rid of those and the formula should count OK.......or you can switch to this version

    =SUMPRODUCT(($C$2:$Z$2=AA$2)*(TRIM($C3:$Z3)={"C";"D";"P";"N"}))

    which uses TRIM in the formula to get rid of any additional spaces - so that should give you the correct count without changing the data

  14. #14
    Registered User
    Join Date
    01-14-2013
    Location
    Chesapeake VA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Countif and Countifs

    Thank you so much! I could have never figured that out by myself. I'm glad you had a way to account for the spaces. Like I said, I inherited this schedule so there is no telling how many cells have trailing spaces in them! Now I have to get back to my patients.

    Best Regards,
    Brian Alexander, alias Provider #1

+ 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