Ghost Sheet

SUMIF or COUNTIF missing rows? Check for trailing spaces

If SUMIF or COUNTIF skips rows that look identical, the text is probably not identical: “Calder Paper ” with a space at the end is a different value from “Calder Paper”. =LEN(A4) shows it, 13 characters instead of 12.

This is the task for this topic. It is part of the plan; the level check before it is free.
H2=SUMIF(A:A,G2,D:D)

Click the sheet or the button: the task opens in your workspace, ready to type

ABCDEFGH
1SupplierInvoiceDateAmountSupplierOwed
2Brightline ChemicalsINV-410111/031,600Calder Paper
3Calder PaperINV-410211/03560Brightline Chemicals
4Marlow PrintINV-410311/03730Osprey Packaging
5Calder PaperINV-410411/041,500Fenwick Tools
6Calder PaperINV-410511/05460Marlow Print
7Osprey PackagingINV-410611/062,220Tidewater Freight
8Calder PaperINV-410711/06520
9Marlow PrintINV-410811/072,290
10Marlow PrintINV-410911/07700
11Osprey PackagingINV-411011/08710
12Tidewater FreightINV-411111/08750
dashed: the answer to reachblack: matchesblue: right after new datared: wrong

Match loosely with =SUMIF(A:A,"Calder Paper*",D:D), or clean the names with TRIM.

See it happen

InvoicesG2=SUMIF(A2:A6,"Calder Paper",D2:D6)
ABCDEFG
1SupplierInvoiceDateAmountCalder Paper
2Calder Paper4101Nov 312003300
3Osprey Packaging4102Nov 3850
4Calder Paper␣4103Nov 4430
5Calder Paper4104Nov 52100
6Calder Paper␣4105Nov 6640
Rows 4 and 6 say “Calder Paper␣”, with a space at the end (␣ marks it; in Excel you see nothing). SUMIF adds only rows 2 and 5: 3,300. The real total for Calder Paper is 4,370.

How to see the space

  • =LEN(A4) returns 13 and =LEN(A2) returns 12. Same word, one more character.
  • =A2=A4 returns FALSE: Excel compares every character.
  • Turn on a filter on column A: the list shows “Calder Paper” twice. Two entries that look the same never are.
  • Check the sum: if your totals per supplier no longer add up to the total of column D, some rows matched nothing.

Three fixes

Match loosely
=SUMIF(A:A,"Calder Paper*",D:D) returns 4,370. The * matches anything after the name, including the space. With the name in a cell: =SUMIF(A:A,G1&"*",D:D)
Trim in the formula
=SUMPRODUCT((TRIM(A2:A6)="Calder Paper")*D2:D6) returns 4,370 without changing the data. TRIM removes spaces at the start and end
Clean the data
Add a column with =TRIM(A2), fill it down, then paste it over column A as values (Home → Clipboard → Paste → Values). Every formula that reads the column is fixed at once

The wildcard has a catch: it also matches longer text that starts the same way. In a status column, =COUNTIF(C:C,"Open*") counts “Open”, “Open ” and also “Opened in error”. In our check it returned 3 where the exact match returned 1. Use it only when no other value starts with the same word, or clean the data instead.

Where the spaces come from

Typical sources are an export from another system, a copy from a web page or email, or someone typing a name. We found no data on how often it happens; what we can say is that nothing in Excel warns you.

What Ghost Sheet doesn’t do

It does not clean your file. It has tasks where a stray space arrives in a later copy of the data, so you learn to write formulas that still work and to check for it.

How we checked

We ran the formulas on this page on the example data in the formula engine Ghost Sheet uses (Univer) on November 24, 2026, except where the page says we could not, and the sheets show the values it returned. That engine is not Microsoft Excel, and we have not re-run these examples in desktop Excel. One known difference: where Excel shows TRUE or FALSE, our engine shows 1 or 0.

Updated