+ Reply to Thread
Results 1 to 7 of 7

Auto Filter with COUNTIF

  1. #1
    Forum Contributor
    Join Date
    05-04-2008
    Posts
    103

    Auto Filter with COUNTIF

    I have an Excel list of students. I am trying to find how many 9th grade students have a "y" in a certain field.

    So I used autofilter and filter the list to give me just the 9th graders which is 703. Then I filtered the column with the "Y" and got 1414. The 1414 is wrong. That is the amount for the whole list, of 9th, 10th, 11th and 12th graders. Since I have only 703 9th graders the number should be less than 703. I used =COUNTIF(D1:D3000,"9") to give me the number of 9th graders and did the same for the "Y" column. What am I doing wrong? It is picking up all the records.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Hi taichi,

    In Excel 2003 and earlier, COUNTIF can only accept one criteria. In your case you have two: one for 9th graders, the other for "Y".

    You might try something like this instead:

    =SUMPRODUCT(($D$1:$D$3000=9)*($E$1:$E$3000="Y"))

    where column E contains your "Y" values (change to your actual column if necessary).

  3. #3
    Forum Contributor
    Join Date
    10-27-2006
    Location
    United Kingdom
    MS-Off Ver
    EXCEL 2003 (2007 at home)
    Posts
    517

    Cool Use the old SUMPRODUCT trick

    There is a trick that can be used when you are trying to count based on multiple criteria.
    In EXCEL TRUE is internally represented as 1, while FALSE is 0 (try typing in -TRUE and -FALSE).

    Thus SUMPRODUCT(-(C2:C45=9),-(F2:F45="Y"))
    gives the number of times a value in C2 to C45 is 9 AND the corresponding value in F2:F45 is "Y".

    Mark.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Hi Mark,

    Can't say I've seen a single '-' used in SUMPRODUCT before. Usually you see none, or a double unary '--'. I assume the double is preferred since the negation of the negation of a number is itself, while a single negation is the opposite of that number.

    With two criteria negated once then multiplied, you should get correct results; but if you added a third you would actually get a negative count.

  5. #5
    Forum Contributor
    Join Date
    05-04-2008
    Posts
    103

    Auto Filter with COUNTIF

    Thank you pjoaquin but I am still getting weird results. I get 351 for a number for 9th graders, and the same for 10th graders. I know that both grades do not have the same amount of "Y" in the columns. What do think it is doing? Thank you for the quick replay.

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    How about posting the two formulas you're using for 9th and 10th graders?

    I would expect them to be identical except for the 9 and 10, e.g.

    =SUMPRODUCT((D1:D3000=9)*(E1:E3000="Y"))

    and

    =SUMPRODUCT((D1:D3000=10)*(E1:E3000="Y"))

  7. #7
    Forum Contributor
    Join Date
    05-04-2008
    Posts
    103

    Auto Filter with COUNTIF

    I apologize. I went back and looked at the code and realized that I had not changed the 9 to a 10 when I did the 10th graders. Thank you for your help. Everything worked great.

+ 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. Auto Filter by Macro
    By ninopalermo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-01-2007, 12:38 PM
  2. auto filter problem
    By Dazza in forum Excel General
    Replies: 1
    Last Post: 05-12-2007, 06:22 PM
  3. Changing Auto Filter Based on User Inputted Cell
    By JohnGuts in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-07-2007, 05:33 PM
  4. Auto Filter
    By JohnGuts in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-01-2007, 04:55 AM

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