+ Reply to Thread
Results 1 to 24 of 24

How to use COUNTIFS to check partial contents of a cell & also multiple criteria in range

  1. #1
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    How to use COUNTIFS to check partial contents of a cell & also multiple criteria in range

    Hey friends! Long time no talk to. Anyway, here's what I'm trying to do. I've attached a workbook.

    Looking at my test workbook, there is a column which has data like "Top", "Bottom", "Side" or "Front". Well, how can I tell COUNTIFS to look for "to" (which should hopefully return results for "Top" and "Bottom", since they both have "to" in them). I feel like this could done using the asterisk to tell it to look for *+to+*, so basically the "to" with any characters before or after it. I'm just not sure exactly how to structure it.

    Also, I know I could use 2 separate functions for this next thing, but what if I wanted to know how to count if a cell range contains totally unrelated data? Like, what if I wanted to know if column B (in my example) contains "B" or "A"? Like, COUNTIFS(B:B, "B" or "A", D:D, "Top") would tell me how many times we have Top in the D column and also A or B in the B column? I know I could do
    Please Login or Register  to view this content.
    and that would work, but is there a way to consolidate it so I don't have to add two different COUNTIFS?
    Attached Files Attached Files

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    so

    =COUNTIFS(D:D,"*to*")

    and, re: 2nd question

    =SUM(COUNTIFS(D:D,"Top",A:A,{"A","B"}))

    note: you're still performing two separate COUNTIFs but, c/o the array constant and outer sum, the syntax is a little more succinct

  3. #3
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,109

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Hi
    In G3:
    SUMPRODUCT(($B$2:$B$21="A")*(($D$2:$D$21="TOP")+($D$2:$D$21="BOTTOM")))
    G7:
    =SUMPRODUCT((($B$2:$B$21="C")+($B$2:$B$21="A"))*(($D$2:$D$21="FRONT")))

    G9:
    =SUMPRODUCT((($B$2:$B$21="B")+($B$2:$B$21="A"))*(($D$2:$D$21="SIDE")+($D$2:$D$21="TOP")))

  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. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,484

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Maybe:

    =SUM(COUNTIFS(D:D,{"Top","Bottom"},B:B,"A"))

    =SUM(COUNTIFS(B:B,{"A","C"},D:D,"Front"))

    =SUM(COUNTIFS(B:B,{"A","B"},D:D,{"Side","Top"}))

    All need to be entered using CTRL+SHIFT+ENTER.
    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 Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,416

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    One correction.

    If there are 2 formula arrays the {} in th emiddle of the formula, the second one needs to be ; separated not , separated.

    =SUM(COUNTIFS(D:D, {"Side","Top"}, B:B, {"A";"B"}))

    It remains an array formula.
    Attached Files Attached Files
    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

  6. #6
    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. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,484

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Thanks, Glenn - oversight on my part.

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    See comparison, here.
    Attached Files Attached Files

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,883

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    I like this as it's more flexible:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  9. #9
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    The array stuff is sorta confusing me. I know what an array is. I've done a bit of programming so I'm not lost on the concept of arrays, but I'll mess with it a little bit and see if I can make some sense of it. Thanks!

  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. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,484

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    The array stuff means what I said when I said this:

    All need to be entered using CTRL+SHIFT+ENTER.

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    To be honest, I'd ultimately go for a more generic approach, myself.

    I'd set up 2 sets of drop down boxes to make the selection of task and location and then use this formula to give me the answer. It is still an array formula:

    =SUM(COUNTIFS(B:B,G1:I1,D:D,TRANSPOSE(G2:I2)))
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Quote Originally Posted by TMS View Post
    I like this as it's more flexible:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Why is the SUM thing necessary? I thought COUNTIFS automatically added together the number of cells in the range that meet the criteria?

    Furthermore, when I use the curly brackets, I'm reading that I must do Ctrl+Shift+Enter. When I do this, Excel slaps Curly brackets on my whole things, even outside the = sign. Is this right?

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    OK. Because you are doing a countifs with OR criteria, you need to wrap it in a SUM to get a total. Otherwise it'll return only one of them.

    The curly brackest inside the array are formula arrays. They give effect (in this case ) to the OR ciriteria. In older (pre Office 365) Excel versions any formula that required recalculations (first count for "Top" and then count for "bottom" are array formulae, and will nto work with enter alone.. They need to be set with CTRL-SHIFT-ENTER. See my standard explanation about array formula:

    You seem to be using an older version of Excel than me. So, please refer to the attached file. If the formulae are enclosed within a pair of { }, these are array formulae.

    These are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see the curly brackets { } appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...

  14. #14
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Thanks Mr. Glenn! It seems to be working, and I think I understand it a lot better now.

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Just in case you missed it... Take a look at post 11. I think it's the most user friendly approach.

  16. #16
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Quote Originally Posted by Glenn Kennedy View Post
    Just in case you missed it... Take a look at post 11. I think it's the most user friendly approach.
    I just grabbed it and I'll take a look. But can you help me understand what's wrong with this formula, and why I'm getting an error?

    Please Login or Register  to view this content.
    I did the Ctrl+Shift+Enter thing and I got a VALUE error here. The two criteria (A:A, "M") and (B1:B5315 looking at that array) seem to work when I do them as individual COUNTIF formulas. But when I combine them in the COUNTIFS, I get the VALUE error.

  17. #17
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Quote Originally Posted by Glenn Kennedy View Post
    Just in case you missed it... Take a look at post 11. I think it's the most user friendly approach.
    I agree. It's definitely user friendly! If I was showing this data to others, I'd want something like this. I might try to incorporate this method. In my real book, there are more than 2 categories that must be counted, but I think I can extrapolate what you've done here into as many categories as needed.

    The only reason it might not work is because I really want a side-by-side comparison tool where we can see all of the numbers lined up next to each other, rather than just selecting one set of criteria to see one product.

    I need to learn more about that TRANSPOSE function! I've never seen it before and I have no clue what it does, but I'm sure there is plenty of material out there to explain it.

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    If you mock up a sheet showing what you really really want (that might make a good song??), I will have a go at doing it.

  19. #19
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Can you take a look at the concerns in #16? If I could figure out why I'm getting this VALUE error, I think I'd have it all set.
    Last edited by AliGW; 12-17-2020 at 12:48 PM. Reason: PLEASE don't quote unnecessarily!

  20. #20
    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. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,484

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    The thing that jumps out at me is that the two arrays are different sizes:

    =SUM(COUNTIFS(A:A, "M", $B$1:$B$5315, {"*Oth*","*know*",""}))

    Try this:

    =SUM(COUNTIFS($A$1:$A$5315, "M", $B$1:$B$5315, {"*Oth*","*know*",""}))

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    I didn't see post 16!! Yes Ali's explanation is probably correct. Did it work?

  22. #22
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,799

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    J3=sumproduct((isnumber(match(d2:d21,d3:d4,0)))*(b2:b21=b2))

    j7=sumproduct((isnumber(match(b2:b21,b14:b15,0)))*(d2:d21=d6))

    j9=sumproduct((isnumber(match(b2:b21,b3:b4,0)))*(isnumber(match(d2:d21,d16:d17,0))))

  23. #23
    Registered User
    Join Date
    10-15-2015
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    83

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Quote Originally Posted by Glenn Kennedy View Post
    I didn't see post 16!! Yes Ali's explanation is probably correct. Did it work?
    Yes, it was the solution! YAY

    Lemme ask one final question:

    What CAN'T you guys do?

    Thanks so much to all!

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

    Re: How to use COUNTIFS to check partial contents of a cell & also multiple criteria in ra

    Well, I can't use VBA.... or turn the clock back 20 years...

+ 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. Countifs: Multiple Criteria in Same Range with Other Criteria
    By ejpal in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-14-2019, 07:16 AM
  2. [SOLVED] COUNTIFS with Multiple Text Criteria in Same Criteria Range
    By xl2016 in forum Excel General
    Replies: 5
    Last Post: 06-18-2017, 05:00 AM
  3. Countifs with multiple criteria in single criteria range
    By SUHAS KARHADKAR in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 12-01-2016, 10:55 AM
  4. Countifs with multiple criteria in single criteria range
    By MCP313 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-01-2016, 03:51 AM
  5. [SOLVED] COUNTIFS with multiple criteria in the same criteria range
    By Faridwahidi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-23-2015, 01:04 PM
  6. [SOLVED] Sumifs using the contents of a cell as a partial criteria
    By JimmyMac22 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-04-2014, 10:02 AM
  7. COUNTIFS with Multiple Criteria in One Range
    By mphillips in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-19-2013, 02:43 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