How to use the COUNTIF function in Excel that refers to a named range that is non-rectangular in shape.

Bruce Whitaker 20 Reputation points
2025-08-24T04:26:06.3033333+00:00

My issue is summed up in this example from Excel.

User's image

Microsoft 365 and Office | Excel | For home | Windows
0 comments No comments
{count} votes

Answer accepted by question author
  1. IlirU 1,436 Reputation points Volunteer Moderator
    2025-08-24T08:56:40.4233333+00:00

    User's image

    If you have selected C2:H3 and G4:H5 or you have selected C2:F3 and G2:H5 and you have formed a named range with the name ATestRange, then the COUNTIF function cannot work, since this function has in its syntax: range and criteria.

    If the named range is not given as a rectangular shape, then the COUNTIF function does not consider the range as a single one, but as multiple ranges and for this reason it cannot work to make the desired calculation.

    In such a case you can use this formula in cell K2:

    =SUM(--(TOCOL(ATestRange, 1) = J2))

    HTH


2 additional answers

Sort by: Most helpful
  1. Srinivasa P 5,575 Reputation points Independent Advisor
    2025-08-24T05:39:29.32+00:00

    Hey there!

    COUNT just looks for numbers, and Microsoft made it flexible to take multiple ranges.

    COUNTIF must apply the condition to every cell in the range, and Excel’s implementation only allows one contiguous block per condition.

    Try this (assuming your value range starts from A1):

    =COUNTIF(Sheet1!$A$1:$D$2,2) + COUNTIF(Sheet1!$D$5:$E$5,2) +COUNTIF(Sheet1!$E$4,2)

    0 comments No comments

  2. riny 20,530 Reputation points Volunteer Moderator
    2025-08-24T06:07:07.27+00:00

    Provided you are on a modern Excel version that supports the LAMBDA functions you try this:

    User's image

    The formula that returns the count (in K2) of the criterion (in J2) is:

    =REDUCE(0,TOROW(testrange),LAMBDA(i, a, i + (a=J2)))

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.