Home » excel » excel – How to compare literals in COUNTIF

excel – How to compare literals in COUNTIF

Posted by: admin April 23, 2020 Leave a comment

Questions:

Named lists in an excel sheet are referenced from another sheet on the same book.

E.g.

Sheet 2 has the named lists(GRPCNT) contain strings

> 5
5 - 9
10 - 20
> 20

Sheet 1 uses GRPCNT to provide a list of options.
Say, there are three rows

A | > 5
B | > 20
C | > 5

Sheet 1 has to determine the number of occurrences of each option from the list.

The problem is

COUNTIF(Range, "> 5") 

returns ‘0’ instead of ‘2’ for the example data above.

I need a literal comparision something along the lines of

COUNTIF( Range, Sheet2!A1 ) , or 
COUNTIF( Range, "'> 5'" )

Both above attempts failed to provide the desired result.

What am I doing wrong here?

How to&Answers:
COUNTIF(Range, "=> 5")

This count how many cells in the range matches (=) the content > 5 (no “=>” is not an operator).

The equal sign is needed because > at the start already has a special meaning: count cells which integer values is greater than 5.