+ Reply to Thread
Results 1 to 12 of 12

Count # of rows that meet a criteria

  1. #1
    Registered User
    Join Date
    01-20-2011
    Location
    Portland, OR, USA
    MS-Off Ver
    Excel 2007
    Posts
    17

    Count # of rows that meet a criteria

    Hi there!

    Excel Spreadsheet example can be downloaded here.

    I need to have a single cell giving me the total number of rows that meet the following criteria:
    1. Row does not contain an "X" in Columns B:F
    2. Row does not contain a number that is <=0 in Columns B:F
    3. Row contains at least one number that >0 in Columns B:F

    In this example the answer would be 2 (Rows 4 and 8).

    Making Column G use a formula for each row and then doing a sum at the bottom is not an option. It needs to be a single cell. Any ideas? Thanks very much for your help. I've been puzzling over this for a while now.

    ~kory
    Last edited by miinstrel; 07-26-2011 at 04:38 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Count # of rows that meet a criteria

    I couldn't figure out how to do this in a single cell without a macro (though someone else might know how). I'm curious as to why it has to be a single cell. There might be other out-of-the-box solutions that would work for you, such as using a different worksheet, or an entirely separate workbook, depending on what your constraints are.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    01-20-2011
    Location
    Portland, OR, USA
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Count # of rows that meet a criteria

    I'd like to avoid a macro just for simplicity's sake, but will use one if necessary. This spreadsheet is just an example of a much larger worksheet (1523 rows and 28 columns) that is part of a series of reports I run regarding product placement for our company. There are already several worksheets in the workbook, so that's why I'd like to avoid adding another. Multiple people access and add information to this including inserting lines and I'd like to avoid the possibility of them forgetting to copy down the formula. That would result in constant upkeep on my part.

    The other reason for using a single cell is that the cell that will be using this formula is actually part of a separate report on a different tab, though it's in the same workbook. It will just be linking to the tab that the example worksheet is on.

    I can usually figure most of the formulas I need out, which means I only ever toss the hard ones out to the interwebs for help. =/

    To re-word my problem which may spark ideas for someone: I need to count the number of times all 3 of the above criteria register "True".
    Last edited by miinstrel; 07-20-2011 at 03:49 PM.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count # of rows that meet a criteria

    Here's my out of the box solution (requires multiple cells)
    I set up the table in I6:L13 but you could set it up on a different sheet or hide the columns.
    Each column of table represents a criteria (3 criteria, 3 columns) and if the row meets that criteria, it imputs a 1.

    Doesn't contain an X
    =--(COUNTIF(B2:F2,"X")<1) dragged down

    Doesn't have a number <= 0
    =--(COUNTIF(B2:F2,"<=0")<1) dragged down

    Has at least 1 number > 0
    =--(COUNTIF(B2:F2,">0")>0) dragged down

    Then using SUMPRODUCT to count times all 3 criteria are met (Cell I6)
    =SUMPRODUCT(J7:J13,K7:K13,L7:L13)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    01-20-2011
    Location
    Portland, OR, USA
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Count # of rows that meet a criteria

    Chemist -

    I think it would be simpler to include all 3 criteria in one cell with:

    =AND(COUNTIF(B3:F3,"X")<1,COUNTIF(B3:F3,"<=0")<1,COUNTIF(B3:F3,">0")>0) and counting how many register "TRUE". Either way my goal is to not have an additional column of data.

    I'm not very familiar with Array Formulas... Might those be useful in this situation?

    Beffudledly,
    ~kory

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count # of rows that meet a criteria

    Agreed with the economy of combining the 3 formulas to 1 cell. I tried coming up with an array formula that would work but could not.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Count # of rows that meet a criteria

    Try:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by NBVC; 07-21-2011 at 10:33 AM. Reason: Uploaded workbook for benefit of users not to have to go to 3rd party location.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  8. #8
    Registered User
    Join Date
    01-20-2011
    Location
    Portland, OR, USA
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Count # of rows that meet a criteria

    NBVC, you sir are a genius. That worked beautifully.

    Was hoping I'd be able to modify this formula slightly, but I'm having difficulty getting the next result needed. How would I modify this to just show how many rows contain a number greater than 1 and remove the other criteria?
    Last edited by miinstrel; 07-22-2011 at 02:23 PM.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Count # of rows that meet a criteria

    The critieria "sections" start with "--" and end with a "," so take out those sections you no longer need.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  10. #10
    Registered User
    Join Date
    01-20-2011
    Location
    Portland, OR, USA
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Count # of rows that meet a criteria

    I tried that actually... seemed simple and logical. Removing the criteria I don't need leaves me with:

    =SUMPRODUCT(--(MMULT(--($B$2:$F$8>0),{1;1;1;1;1})>0))

    Which should give a result of 4, but is giving a result of 6 because it's also using any cell containing "X". How would I stop that?

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Count # of rows that meet a criteria

    For that try:

    =SUMPRODUCT(--(MMULT(($B$2:$F$8>0)*(B2:F8<>"X"),{1;1;1;1;1})>0))

  12. #12
    Registered User
    Join Date
    01-20-2011
    Location
    Portland, OR, USA
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Count # of rows that meet a criteria

    Awesome! You guys have made this workbook a thing of beauty. Thank you once again.

+ 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