Flag a double-booked order (COUNTIF)
The problem
Problem statement
A customer swears they were charged twice, and the order log looks suspicious: order ID ORD-1042 might have been booked more than once. Before refunding anything, count how many rows in A2:A11 carry that exact ID. The disputed ID is already sitting in D1. Put the answer in the D2 cell D2.
The criteria is text: quote the order ID (or point at the cell holding it) — case 3 appears once, so 1 is correct.
Problem data
Show the sheet as a table (selectable, copyable)
| A | B | D | |
|---|---|---|---|
| 1 | Order ID | Amount | ORD-1042 |
| 2 | ORD-1037 | 120 | |
| 3 | ORD-1042 | 250 | |
| 4 | ORD-1051 | 89 | |
| 5 | ORD-1042 | 250 | |
| 6 | ORD-1063 | 340 | |
| 7 | ORD-1078 | 150 | |
| 8 | ORD-1090 | 99 | |
| 9 | ORD-1104 | 210 | |
| 10 | ORD-1119 | 175 | |
| 11 | ORD-1125 | 60 |
Notes
COUNTIF's second argument is the criteria. Text criteria needs quotes: "ORD-1042". The match is exact (but not case-sensitive): "ord-1042" works too. This is the same engine behind conditional formatting's Duplicate Values rule and Sheets' custom formula =COUNTIF($A$2:$A$11,A2)>1 — count first, then act.
How to approach
Your answer goes in D2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.
- Target cell is D2
- The range to count over is A2:A11
- The criteria is the order ID as text — quote it, or point at the cell that holds it
- Shape:
=COUNTIF(?, ?)— range first, then the criteria
Official solutions
Show 2 solutions — try it yourself first
Approach 1: COUNTIF with the order ID as text criteria
=COUNTIF(A2:A11, "ORD-1042")
COUNTIF walks A2:A11 and counts every cell equal to "ORD-1042". Two matches means the order really was booked twice — time to escalate before refunding.
Approach 2: point the criteria at a label cell
=COUNTIF(A2:A11, D1)
D1 already holds the order ID, so the criteria can reference it directly. When tomorrow's complaint is about ORD-1051, just change D1 — the formula never needs editing.
Function guide
FAQ
How do I find duplicates in Excel with COUNTIF?
Add a helper column with =COUNTIF($A$2:$A$11,A2) and fill down — any value greater than 1 is a duplicate. Filter or conditional-format on that column to see them all at once.
How do I highlight duplicates in Google Sheets?
Select the range, then Format → Conditional formatting. Under Format rules choose Custom formula is and enter =COUNTIF($A$2:$A$11,A2)>1, then pick a fill color.
Is COUNTIF case-sensitive?
No. "ORD-1042" and "ord-1042" both match. If you ever need a case-sensitive count, use SUMPRODUCT with EXACT: =SUMPRODUCT(--EXACT(A2:A11,"ORD-1042")).