+ Reply to Thread
Results 1 to 9 of 9

Countif in arrays with two conditions

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Countif in arrays with two conditions

    Hello everyone

    In this link I have put the same issue
    http://www.eileenslounge.com/viewtopic.php?f=30&t=25267


    But I don't need to rely on cells (colored cells are not required)

    First have a look at this code that count the range("B8:AP8") on a criteria 4,3,2,1,0 ..Run the demo code to see the results in range("AR7:AV8")
    I need to extend the criteria ..
    To count if :
    ---------------
    range("B8:AP8") on a criteria 4,3,2,1,0
    range("B7:AP7") has one of the values in range("B1:F1")

    The expected results would be like that snapshot

    Untitled.png

    for example : the number 3 happened 13 times in range("B8:AP8")
    And in range("X7:L7") the numbers 16 & 18 & 26 & 28 occurs in this range
    So the result for 3 is 4
    Hope it is clear
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Countif in arrays with two conditions

    The standard way to do it is to create multiple COUNTIFS and add them together eg
    Please Login or Register  to view this content.
    However, I believe that some form of SUMPRODUCT can do it a bit neater.....Im not clever enough on a Monday morning to do it though
    If someone has helped you then please add to their Reputation

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Countif in arrays with two conditions

    Hi,

    You might use a formula such as this
    =SUMPRODUCT(COUNTIFS($B$8:$AP$8,AR7,$B$7:$AP$7,$B$1:$F$1))
    unless you specifically require a UDF.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Countif in arrays with two conditions

    Quote Originally Posted by xlnitwit View Post
    Hi,

    You might use a formula such as this
    =SUMPRODUCT(COUNTIFS($B$8:$AP$8,AR7,$B$7:$AP$7,$B$1:$F$1))
    unless you specifically require a UDF.
    Cant believe I was so close, for some reason i was sure you needed {} around the range $B$1:$F$1 but couldnt get it to work, didnt even bother trying it without!

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Countif in arrays with two conditions

    You only use the {} notation with array constants- such as {1,2,3}- not with ranges.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Countif in arrays with two conditions

    Thanks a lot for reply
    I prefer using UDF if possible. If you looked at the other thread you will find some clues but not the final yet
    Thank you very much for sharing

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Countif in arrays with two conditions

    Quote Originally Posted by YasserKhalil View Post
    I prefer using UDF if possible.
    It will be less efficient to do so- is that not a concern?

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Countif in arrays with two conditions

    In fact, it is a part of huge project I am working on and no place for formulas .. I previously relied on formulas and it was a disaster when the data get bigger. I will need to do the task many many times so I think udf will be very helpful
    I will not use it in sheet directly. It will be part of other codes

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Countif in arrays with two conditions


+ 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. [SOLVED] Countif using vba arrays
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-10-2016, 09:20 PM
  2. COUNTIF(?) For Multiple Arrays With Multiple Conditions
    By MJ10 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-09-2014, 10:07 PM
  3. [SOLVED] CountIF VBA Arrays
    By lloydgodin in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-26-2013, 08:09 PM
  4. Help with multiple conditions and arrays
    By Blackhawks in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-13-2013, 03:33 PM
  5. [SOLVED] COUNTIF and arrays?
    By aikorei in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-16-2012, 11:27 AM
  6. Conditional formatting multiple conditions (arrays?)
    By Pyrex238 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2011, 02:54 PM
  7. Counting conditions in arrays
    By Steven Fleck in forum Excel General
    Replies: 1
    Last Post: 12-04-2007, 04:10 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