Key Takeaways
- One conditional formatting rule colours exact repeats with COUNTIF, a second rule uses a TRIM and LOWER helper column for repeats that differ by spacing or case, and a third rule colours near matches using a helper score.
- The worked example uses six names where three rows score 0.90 against an earlier row, so a cut-off of 0.85 flags all three.
- The score is a standard Levenshtein similarity written once in Apps Script and called as =MAXSIM(A2,$A$2:A2).
- A flag means review, not automatic deletion, because the sample includes names whose similarity comes from a shared surname rather than a shared person.
Three conditional formatting rules colour exact repeats, normalised repeats and near matches.
| Rule | Exact formula |
|---|---|
| Exact duplicates | =COUNTIF($A$2:$A,$A2)>1 |
| Normalised repeats | =COUNTIF($C$2:$C, $C2)>1 |
| Near matches | =$B2>=0.85 |
What you should see: A6 and A7 red, three amber rows at 0.90 and no colour on the unrelated name.
What You Will See
By the end of this page, column A shows six names, column B shows a similarity score and column C holds a normalised helper value. The sheet colours exact repeats, normalised repeats and near matches in separate colours. Every score in the tables below is the output of the function printed here.
The Sample Rows
Type these six values into A2:A7 of a blank sheet. They are chosen so that exact repeats, spelling variants and one unrelated name all appear together.
| Cell | Name | Why it is here |
|---|---|---|
| A2 | Jon Smith | First occurrence |
| A3 | John Smith | One letter added |
| A4 | John Smyth | One letter changed |
| A5 | Jon Smyth | Same sounds in a different combination |
| A6 | Jane Doe | Unrelated name |
| A7 | Jane Doe | Exact repeat of A6 |
Rule 1, Exact Duplicates
- Select
A2:A7. - Open Format, Conditional formatting.
- Under Format cells if, choose Custom formula is.
- Enter
=COUNTIF($A$2:$A,$A2)>1. - Choose a light red fill, then select Done.
A6 and A7 turn red. A2 to A5 stay uncoloured even though four of them describe the same person, which is exactly the gap the next rule fills.
Rule 2, Repeats That Differ by Case or Spacing
The exact rule misses values that read the same but carry extra spaces or different case. Add a normalised helper column before changing the COUNTIF rule, and keep the exact rule in place as a separate colour.
- In C2 enter
=LOWER(TRIM(A2))and fill down to C7. TRIM removes doubled and edge spaces and LOWER makes the case consistent. - Select
A2:A7, open Format, Conditional formatting, choose Add another rule and then Custom formula is, and enter=COUNTIF($C$2:$C, $C2)>1. Choose a light blue fill and save. - Read the helper value beside each shaded row.
One worked row shows the effect. Put Acme Corp in A2, and cell C2 reads acme corp. A second row holding acme corp produces the same helper value, so the COUNTIF rule shades both rows even though column A holds two different strings.
This rule catches spacing and case differences only. It cannot connect Jon Smith with John Smith, which is what the near-match rule below does.
A Similarity Score With Apps Script
Open Extensions, Apps Script, paste both functions below, save and reload the sheet. MAXSIM compares the current cell with every cell above it and returns the highest Levenshtein similarity.
/**
* Returns the highest similarity between a value and earlier cells.
* @param {string} value The current cell value.
* @param {Array<Array<string>>} range Earlier rows in one column.
* @returns {number} The highest score from 0 to 1.
*/
function MAXSIM(value, range) {
const text = String(value).toLowerCase().trim();
let best = 0;
range.forEach(function (row) {
const other = String(row[0] || "").toLowerCase().trim();
if (other && other !== text) {
best = Math.max(best, similarity(text, other));
}
});
return best;
}
/**
* Returns Levenshtein similarity between two strings.
* @param {string} a First string.
* @param {string} b Second string.
* @returns {number} A score from 0 to 1.
*/
function similarity(a, b) {
const row = Array.from({ length: b.length + 1 }, (_, j) => j);
for (let i = 1; i <= a.length; i++) {
let prev = row[0];
row[0] = i;
for (let j = 1; j <= b.length; j++) {
const old = row[j];
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, prev + cost);
prev = old;
}
}
const distance = row[b.length];
const longer = Math.max(a.length, b.length);
return longer === 0 ? 1 : 1 - distance / longer;
}
In B2 enter =MAXSIM(A2,$A$2:A2) and fill down. The growing range is deliberate: each row is compared only with rows above it, so the later row of a pair is the one that gets flagged.
Rule 3, Near Matches
- Select
A2:A7again. - Open Format, Conditional formatting and choose Add another rule.
- Choose Custom formula is and enter
=$B2>=0.85. - Choose a light amber fill, then select Done.
The dollar sign before B fixes the column while the row number moves with each cell. A rule written as =B2>=0.85 would drift across all six columns of the selected range and colour the wrong cells.
The Expected Result
| Name | MAXSIM score | Colour |
|---|---|---|
| Jon Smith | 0.00 | None, first row has no earlier comparison |
| John Smith | 0.90 | Amber, near match with A2 |
| John Smyth | 0.90 | Amber, near match with A3 |
| Jon Smyth | 0.90 | Amber, near match with A3 and A4 |
| Jane Doe | 0.22 | None |
| Jane Doe | 0.00 | Red, exact repeat of A6 |
A2 scores zero because the range ends at its own row. A7 scores zero from the similarity helper because its only earlier equal is excluded by the other !== text guard, but the exact rule still colours it red. If you want A7 to score 1.00 as well, remove that guard and accept that identical rows appear in both colours.
The names stay in your own Google Sheet, and the score column records why a row was coloured.
A threshold is the score a pair must reach before you accept it, and 0.85 is a starting point chosen from this sample. Raise it when the amber list contains unrelated names and lower it when obvious variants are missing. Read ten flagged rows before applying a cut-off to a full column.
Using Flookup Scores Instead
The script is useful when you want to see the arithmetic. If you would rather skip the script, Flookup Data Wrangler provides FUZZYSIM as a cell formula and FLOOKUP to return the closest value from a table. The same conditional formatting rule then points at the Flookup helper column.
Either way, keep the score visible next to the name. Conditional formatting without a score tells you that something is similar but not why, which makes a threshold hard to defend later.
Frequently Asked Questions
How do I highlight exact duplicates in Google Sheets?
Select A2:A7, open Format, Conditional formatting, choose Custom formula is and enter =COUNTIF($A$2:$A,$A2)>1. Pick a fill colour and save. Both occurrences of a repeated value are coloured because the rule checks the whole column.
How do I highlight near matches rather than only exact duplicates?
Add a helper column with a similarity score, then base the formatting rule on that column. The worked example uses =MAXSIM(A2,$A$2:A2) with an Apps Script Levenshtein function and colours any row scoring 0.85 or more.
Why not just lower the exact-match rule?
An exact-match rule cannot see that Jon Smith and John Smith are close. A similarity score measures the difference and lets you choose a cut-off. Keep the exact rule as a separate colour so the two kinds of finding stay distinct.
Which Flookup functions help with fuzzy comparison?
FUZZYSIM returns a similarity score between two values and FLOOKUP finds close matches in a table. The script on this page gives the same kind of score without installing anything, which is useful when you want to see the arithmetic first.
You Might Also Like
About the Author
Andrew Apell is the creator of Flookup Data Wrangler and has built data cleaning tools for Google Sheets since 2018.
Every Flookup result described here can be checked in the documentation.
Read
Our Story
for the background or
contact the team
with any questions about this post, including corrections, unclear steps or use cases we have not covered yet.