Excel Guide · Prompt: “Flag each row in A2:A6 as "Duplicate" if the value appears more than once, otherwise "Unique"”
Detect and Flag Duplicate Values in Excel with COUNTIF
Verified by LiveFormulaLab Engineering Team • Updated November 2026
Detect and highlight duplicate emails, SKUs, or transaction IDs in Excel using COUNTIF. Copy the formula and test live in our sandbox.
Verified Excel Syntax
=IF(COUNTIF($A$2:$A$6, A2) > 1, "Duplicate", "Unique")How This Formula Works (Step-by-Step)
COUNTIF counts how many times the current row value appears across the entire locked column.
Step 1: Lock the full column ($A$2:$A$6) and compare it against the current row (A2).
Step 2: Whenever the count exceeds 1, return "Duplicate"; otherwise return "Unique".
Formula Syntax & Arguments Breakdown
Locks the full key range ($A$2:$A$6) inside COUNTIF against the current row cell (A2) so any value appearing two or more times is flagged immediately.
| Argument / Clause | Requirement | Data Type | Role & Behavior |
|---|---|---|---|
range ($A$2:$A$6) | Required | Locked Range | Absolute range containing all IDs, emails, or order numbers checked for repetition. |
criteria (A2) | Required | Relative Cell | Current row value checked across the entire locked list. |
threshold (> 1) | Required | Comparison | Evaluates TRUE whenever two or more identical values exist anywhere in the range. |
3 Real-World Use Cases
- Preventing double-billing by checking duplicate invoice IDs before payout.
- Cleaning duplicate customer email entries in marketing lists.
- Spotting repeated SKU codes in warehouse cycle counts.
Cross-Platform Equivalents
- Excel
=IF(COUNTIF($A$2:$A$6, A2)>1, "Duplicate", "Unique")- SQL
SELECT transaction_id, COUNT(*) FROM transactions GROUP BY transaction_id HAVING COUNT(*) > 1;- Python Pandas
df['Status'] = np.where(df['Transaction ID'].duplicated(keep=False), 'Duplicate', 'Unique')
Common Mistakes & Pro Tips
Pitfalls & How to Fix Them
Mistake: Using COUNTIF(A2:A6, A2) without $ locks misses earlier rows as you copy the formula down.
Fix: Always lock both ends of the search range ($A$2:$A$6) while keeping the single-cell criteria relative (A2).
Mistake: Checking 16+ digit numeric IDs (like credit cards or tracking numbers) causes COUNTIF to falsely treat numbers differing only in the last digits as duplicates because Excel converts strings to 15-digit floats.
Fix: Use =SUMPRODUCT(--($A$2:$A$6=A2))>1 for exact string comparison on long numeric IDs.
Mistake: Duplicate counts treat "abc" and "ABC" as identical because COUNTIF is case-insensitive.
Fix: Use =SUM(--EXACT($A$2:$A$6, A2))>1 when case sensitivity matters (e.g. Base64 tokens or short IDs).
Engineering Pro Tips
- To flag only the 2nd+ repeat occurrence while keeping the first occurrence marked "Original", lock just the top cell: =IF(COUNTIF($A$2:A2, A2)>1, "Duplicate", "Original").
- Paste =COUNTIF($A$2:$A$1000, $A2)>1 directly into Conditional Formatting > New Rule > Use a formula to highlight duplicate rows in color.
- To check uniqueness across two combined columns (e.g., First Name + Email), use COUNTIFS($A$2:$A$6, A2, $B$2:$B$6, B2)>1.
Frequently Asked Questions
- How do I flag only the second and later occurrences as duplicates?
- Use an expanding range: =IF(COUNTIF($A$2:A2, A2) > 1, "Duplicate", "First").
- Can I use this same formula in Conditional Formatting?
- Yes! Use =COUNTIF($A$2:$A$100, A2) > 1 as a custom formatting rule.
- Is COUNTIF case-sensitive?
- No, COUNTIF treats "abc" and "ABC" as identical.
Related Formulas & Guides
- How to Do VLOOKUP with Multiple Criteria in Excel — Learn how to run a multi-criteria lookup in Excel using XLOOKUP or INDEX/MATCH without helper columns. Copy and test live in our sandbox.
- Extract Domain Name From an Email Address in Excel — Extract company domains from email addresses in Excel using TEXTAFTER or RIGHT/FIND. Copy the verified formula and test with live rows.
- Excel SUMIFS Between Two Dates (Start & End Date) — Sum sales or expenses between a start date and end date in Excel with SUMIFS. Includes live editable date grid and SQL/Sheets equivalents.
- Two-Way Matrix Lookup with INDEX and MATCH in Excel — Perform a 2D row and column matrix lookup in Excel using INDEX and two MATCH calls. Interactive spreadsheet sandbox included.