+ Reply to Thread
Results 1 to 14 of 14

Countif function throwing error with named range

  1. #1
    Registered User
    Join Date
    10-15-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Countif function throwing error with named range

    Hi all,

    Stumped on this one. I have a named range "metrics" which evaluates to the values {3367,1066,789,496,496,379,371}. (The named range definition is a formula using the LARGE function to sort the results of an OFFSET lookup.)

    I want to count the number of times a particular value appears in the array of values, so I expect this to work:

    =COUNTIF(metrics,496)

    This returns a #VALUE error. Using Excel's Evaluate Formula tool, I see the named range expand out to the array of values just fine, then the COUNTIF function throws the error. Everything I've seen around the net indicates COUNTIF should work with a named range.

    There's no problem with the named range and it refers to numbers (ex. =SUM(metrics) evaluates no problem). I'm happy to post a sample workbook if it'd be helpful.

    Any idea what's going on here? I'd appreciate any insight!

    Thanks,
    Keith

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Countif function throwing error with named range

    Try this one.

    =COUNTIF(metrics,"496")

  3. #3
    Registered User
    Join Date
    10-15-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Countif function throwing error with named range

    Hi Oeldere,

    Tried that, same result. I also tried putting my criteria in a cell, =COUNTIF(metrics,E2) and that failed.

    The only thing I've found to work is dumping the named range back out into cell values (ex. A2:A8={metrics}) and running COUNTIF on the explicit range, =COUNTIF(A2:A8,496) which of course defeats the point of using a named range.

    Thanks!

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Countif function throwing error with named range

    Is the named range contiguous?

  5. #5
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: Countif function throwing error with named range

    If the name defined by LARGE function, you can't use COUNTIF. COUNTIF only work with RANGES not with Arrays. try with SUMPRODUCT

    =SUMPRODUCT((metrics=496)+0)
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Countif function throwing error with named range

    Further to Haseeb's point, it sounds like you have a named formula, not a named range, and COUNTIF, like some other functions (RANK, OFFSET, SUMIF, ...), require ranges.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    10-15-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Countif function throwing error with named range

    Hi Cutter,

    Sort of. The definition is =LARGE(unorderedMetrics,ROW(1:16))

    The definition of the named range unorderedMetrics is =OFFSET(ref point,0,MATCH(date,range of dates,0),50,1)

    So, unorderedMetrics returns an array of 50 unordered values (selection of contiguous cells in a column, based on matching a date in a header row of dates) and metrics returns the largest 16 of those values.

    Clear as mud? :-) I've attached a workbook with the problem extracted and replicated.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-15-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Countif function throwing error with named range

    Haseeb, shg,

    Thanks for joining in! That seems to be the problem - COUNTIF expecting a range, not a named formula.

    I'm still not necessarily clear on the difference between a range and an array (is it that an array has no address associated with each value?).

    I don't suppose there's an easy work-around for converting the values of a named formula into a range?

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Countif function throwing error with named range

    You know what a range is -- it's a bunch of cells on a worksheet. A range has an address, a count of cells, cell formatting, ...

    An array is a bunch of values (an array constant, or the result of an array formula) that don't live on a sheet.

    I don't suppose there's an easy work-around for converting the values of a named formula into a range?
    Select 16 cells in a single column and array-enter

    =metrics
    Last edited by shg; 06-08-2012 at 07:40 PM.

  10. #10
    Registered User
    Join Date
    10-15-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Countif function throwing error with named range

    shg - any way to do that without throwing the named formula results into cells on the page?

    All - I'm going to mark this solved. It came out of my attempts to solve this problem http://www.excelforum.com/excel-gene...08#post2817608.

    Thanks again for your help!
    Keith

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Countif function throwing error with named range

    Is there any way to make an array into a range other than by putting it into a range? If there were, "range" would have to have a different definition, n'est-ce pas?
    Last edited by shg; 06-11-2012 at 11:48 AM.

  12. #12
    Registered User
    Join Date
    10-15-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Countif function throwing error with named range

    LOL Fair enough, and nicely phrased! :-)

  13. #13
    Registered User
    Join Date
    12-17-2013
    Location
    Pune,India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Countif function throwing error with named range

    Hi,
    I was getting the same value error for ditto formulae, I had a formulae =COUNTIFS(_5.1_Owner,$A19,Result_5.1,D$18).

    Here, for the second named range, it had lesser range than first. When 2nd named ranges was made to refer to exact same range, the problem disappeared!

    Thanks,
    Narendra

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Countif function throwing error with named range

    Narendra,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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