+ Reply to Thread
Results 1 to 10 of 10

Countif not counting when formula in range

  1. #1
    Forum Contributor
    Join Date
    11-23-2015
    Location
    Yada, Wales
    MS-Off Ver
    Office 2013
    Posts
    176

    Countif not counting when formula in range

    It seems that countif is not counting when I have a formula in my range.
    Can I somehow make it count even though cells in same column contains formula?
    Attached Files Attached Files

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

    Re: Countif not counting when formula in range

    The formula in B8 is a circular formula, it is trying to reference cell B8, too, the same cell the formula is in. If you change this formula to some other NON-circular formula, your countif formula will work. Also, the COUNTIF() in B1 needs to be moved out of column B as well.
    _________________
    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!)

  3. #3
    Forum Contributor
    Join Date
    11-23-2015
    Location
    Yada, Wales
    MS-Off Ver
    Office 2013
    Posts
    176
    Quote Originally Posted by JBeaucaire View Post
    The formula in B8 is a circular formula, it is trying to reference cell B8, too, the same cell the formula is in. If you change this formula to some other NON-circular formula, your countif formula will work. Also, the COUNTIF() in B1 needs to be moved out of column B as well.
    Is there another way for me to count all cells with abc in same column, even when there are formulas below?

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

    Re: Countif not counting when formula in range

    Yes, any formula that is not a CIRCULAR formula (a formula that references it's own cell address in the formula somewhere) will work fine with COUNTIF().

  5. #5
    Registered User
    Join Date
    09-12-2016
    Location
    England
    MS-Off Ver
    2010
    Posts
    5

    Re: Countif not counting when formula in range

    try ?


    =IF(COUNTIF(B2:B1000,"abc")=0,"",COUNTIF(B2:B1000,"abc"))

  6. #6
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Countif not counting when formula in range

    You can use this formula in B1 :
    Please Login or Register  to view this content.

  7. #7
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Countif not counting when formula in range

    Quote Originally Posted by sanram View Post
    Please Login or Register  to view this content.
    This is an incredibly resource-heavy construction, since, by referencing an entire column within the LOOKUP portion, you are forcing Excel to calculate all 1048576 cells in that column.

    What's more, it's not necessary, since COUNTIF(S), SUMIF(S), etc. have a major advantage over most functions in that they suffer no detriment to performance if entire columns are referenced. Hence, you can simply use:

    =IF(COUNTIF(B2:B1048576,"abc")=0,"",COUNTIF(B2:B1048576,"abc"))

    which will be far, far quicker to calculate than your version.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  8. #8
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Countif not counting when formula in range

    Quote Originally Posted by XOR LX View Post
    This is an incredibly resource-heavy construction
    Sorry to say that this is not that heavy. Here
    Please Login or Register  to view this content.
    is calculating the last used row. So if the last used row in column B is 9 then it will calculate up to 9 only. But with your formula you are forcing to calculate all 1048576 rows. So logically my formula should work faster than you. But at this time I am not able to check the calculation speed as I am little busy.

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Countif not counting when formula in range

    Quote Originally Posted by sanram View Post
    So if the last used row in column B is 9 then it will calculate up to 9 only.
    Not true. It will calculate over all 1048576 rows, irrespective of where the last-used row is.

    Quote Originally Posted by sanram View Post
    But with your formula you are forcing to calculate all 1048576 rows.
    Again, not true. The family of functions COUNTIF(S), SUMIF(S), AVERAGEIF(S), etc. use implicit detection of the last-used cell for the range(s) passed, which means that you can arbitrarily reference ranges as large as you like, with no detriment to performance. Which, as I said, is not at all the case with your construction.

    Regards

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Countif not counting when formula in range

    Quote Originally Posted by sanram View Post
    Sorry to say that this is not that heavy. Here

    LOOKUP(2,1/(B:B<>"")

    is calculating the last used row. So if the last used row in column B is 9 then it will calculate up to 9 only.
    Incorrect.

    That formula will evaluate EVERY cell it references, in this case the ENTIRE column.

    As a test I entered XX in cell B9.

    Then, I timed these 2 formulas:

    Formula1: =LOOKUP(2,1/(B:B<>""),B:B)
    Formula2: =LOOKUP(2,1/(B1:B25<>""),B1:B25)

    I ran 5 times for each and averaged the results:

    Formula1: 0.09364 (seconds)
    Formula2: 0.00079 (seconds)

    So, if the formula only evaluated the used range then both formulas should have (nearly) identical calculation times which they do not.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

+ 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. Replies: 5
    Last Post: 05-04-2015, 04:36 PM
  2. Countif counting a data range
    By Muddle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-06-2014, 04:25 PM
  3. [SOLVED] countif formula not counting
    By Chris Manion in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-11-2014, 12:25 PM
  4. [SOLVED] Countif Formula counting balnks
    By ensmith in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-11-2014, 10:37 AM
  5. [SOLVED] countif formula is counting off by 2
    By wangstar in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-30-2013, 02:32 PM
  6. Replies: 8
    Last Post: 02-21-2012, 11:11 AM
  7. CountIf formula - Counting entries by the day of the week
    By IcemanFTW in forum Excel General
    Replies: 6
    Last Post: 03-03-2011, 01:04 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