COUNTIF needs text criteria inside double quotes: =COUNTIF(A2:A20,”East”) counts the East rows, while a COUNTIF with the quotes missing either errors or counts something else entirely. AI-written formulas often drop the quotes around words or put them around numbers that do not need them. Read the criteria argument before trusting the count.
What you need
- The AI-written COUNTIF formula
- The range it counts, with the values visible
- A hand count of the matching rows to compare against
Step 1: Read the criteria argument in the formula bar
Click the formula cell and read the second argument. Text criteria must be in double quotes, comparison criteria such as “>100” must be quoted as one piece, and a plain number needs no quotes at all.
Step 2: Count the matching rows by hand
Filter or sort the range and count by hand how many rows meet the condition. Write the hand count down before looking at the formula result, so a wrong count cannot anchor your check.
Step 3: Fix the quotes and re-check the count
Rewrite the formula with the criteria quoted correctly and compare the new result with your hand count. If they still differ, check for trailing spaces or case differences in the counted values.
Worked example: synthetic region list
The table below is a synthetic example. It shows the expected result of checking an AI-written COUNTIF; no formula was run.
| Check | Value | Result |
|---|---|---|
| Rows with region East, counted by hand | 6 | Hand count |
| AI formula as written | =COUNTIF(A2:A20,East) | Missing quotes |
| AI formula result | #NAME? | Error, not a count |
| Corrected formula | =COUNTIF(A2:A20,”East”) | Criteria quoted |
| Corrected result | 6 | Matches the hand count |
Expected result (UNTESTED). the AI formula as written returns #NAME? because East has no quotes; the corrected formula =COUNTIF(A2:A20,”East”) returns 6, which matches the hand count. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- COUNTIF is not case-sensitive, so it counts East and EAST together; use EXACT for a case-sensitive count.
- A criteria string longer than 255 characters returns a wrong result; split long criteria with concatenation.
- COUNTIF counts what the cells contain, not how they are formatted; a number stored as text will not match a numeric criterion.
- Quoting a number criterion as text, such as “100”, counts text values only, not the number 100.
