← All how-to recipes

How to count cells not equal to a value

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Count every cell except those matching a specific value.

The formula

AppFormulaNotes
Excel (desktop)=COUNTIF(A2:A6,"<>apple")The not-equal operator is <> inside the quoted criterion.
Google Sheets=COUNTIF(A2:A6,"<>apple")Identical.
LibreOffice Calc=COUNTIF(A2:A6,"<>apple")Identical.

How it works

COUNTIF's criterion accepts <> for "not equal": three cells (banana, cherry, banana) aren't "apple". Caution: <> also counts BLANK cells in the range as not-equal — add -COUNTBLANK(A2:A6) if you only want non-blank mismatches. To reference a cell, concatenate: =COUNTIF(A2:A6,"<>"&C1).

Verified, not just documented

We ran =COUNTIF(A2:A6,"<>apple") in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 3 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 3 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

COUNTIF — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons