Google Sheets COUNTIF Wildcards Match Too Much: Escape Literal Characters
🔍 WiseChecker

Google Sheets COUNTIF Wildcards Match Too Much: Escape Literal Characters

COUNTIF treats asterisk and question-mark characters as wildcards in text criteria. If a literal code contains them, escape those characters rather than broadening the match accidentally.

ADVERTISEMENT

Understand what the pattern means

An asterisk matches any sequence of characters, including none. A question mark matches one character. A criterion such as "A*" therefore means more than the literal two-character value A followed by an asterisk.

COUNTIF is not case-sensitive. If your identifier policy distinguishes letter case, ordinary COUNTIF alone is not a sufficient exact-string duplicate test for that policy.

Escape literal special characters

Use a tilde before a literal wildcard. =COUNTIF(A2:A100,"A~*") counts the literal text A*. To match a literal question mark, use ~?; to match a literal tilde, use ~~.

For criteria assembled from input cells, account for all three characters in a reviewed escaping step. Do not assume adding one tilde at the beginning protects special characters appearing elsewhere in the key.

ADVERTISEMENT

Test near matches

Use a small list containing A*, A1, ABC, and an unrelated value. Compare the wildcard count with the literal count. Include a literal tilde and question mark if the real source can contain them.

Check that the range includes the intended records and excludes its header. A formula can be correct for a pattern but wrong for a business question requiring exact equality. Document whether a criterion is a search pattern or a literal key so later editors do not remove the escape characters as apparent punctuation errors.

References

Reviewed against the linked official product guidance on November 3, 2026. Features, limits, screen labels, and access can vary by account, platform, region, and organization policy.

ADVERTISEMENT