Duplicate detection, grouping, and report export
Macro For Removing Duplicates In Google Sheets
Use a read-only duplicate check for macro for removing duplicates in google sheets when you need to inspect repeated values without changing the source sheet. Paste the relevant data, select the key scope, review grouped counts and row indexes, and export the evidence.
Report reading guide
Read duplicate results in three passes
- Scope: confirm selected key columns.
- Groups: review repeated values and counts.
- Rows: compare source row numbers before acting.
A macro for removing duplicates in Google Sheets can repeat a recorded cleanup, but inspect duplicate groups before running it on shared or changing data. Start with a read-only report, decide which columns define a duplicate, and test the removal steps on a copy before recording or replaying them.
This read-only checker scans pasted CSV or TSV data by selected columns, returning grouped counts and row indexes without altering your sheet.Define duplicates before recording a macro
A duplicate can mean a repeated value in one column or a row that matches another row across several columns. For example, two orders with the same email address may be legitimate if their order IDs differ. If order ID is the key, matching email addresses alone are not a reason to delete either order.
Choose the data range and key columns before checking the spreadsheet. Include every column needed to review each record, even if only one column defines a match. Keep a stable identifier with each row so you can trace a reported match after sorting or filtering.
Normalize the selected values
Inconsistent spaces and capitalization can hide matches. To create a comparison key from values in A2:A, put this formula in an empty helper column on row 2 and fill it down:
=IF(A2="","",LOWER(TRIM(A2)))
TRIM removes leading and trailing spaces and reduces repeated ordinary spaces; LOWER converts text to lowercase. The original values remain unchanged. Blank source cells produce blank keys, so they do not become a duplicate group in the examples below.
Normalization changes the meaning of the comparison. Check whether case, extra spaces, leading zeros, or formatting carry meaning in your data set. TRIM does not remove every kind of whitespace, and visually similar values can still differ; inspect suspicious entries rather than assuming the helper column catches every variant.
Group and count matches
Assume normalized keys are in D2:D. Put this formula in an empty area to list nonblank keys and their group counts: google-sheets-removing-duplicates
=QUERY(D2:D,"select D, count(D) where D is not null group by D having count(D) > 1 label D 'Key', count(D) 'Count'",0)
Each result row represents one repeated key, and its count includes the first occurrence. A count of three means three source rows share that key, not that all three should be removed. Leave enough empty space for the result to expand.
To label individual rows, enter this formula in E2 and fill it down:
=IF(D2="","",IF(COUNTIF($D$2:$D,D2)>1,"Duplicate","Unique"))
COUNTIF checks the whole key range, so every member of a duplicate group receives the same label. Filter the label column to inspect matching rows alongside their IDs and other fields. These formulas compare a single helper key; for a multi-column definition, use a method that preserves the boundary between fields rather than concatenating values ambiguously. removing-duplicates-on-google-sheets
Inspect the report before removing duplicates
Review each group against the original records before deleting anything. For a customer list, compare names, contact details, and update dates; repeated keys can point to conflicting records that need a human decision rather than automatic removal.
- Confirm the selected range includes all rows and the correct header treatment.
- Check that the key columns match the business rule for duplicates.
- Review group counts and source row indexes or stable IDs against the sheet.
- Decide which record to retain and how to handle conflicting values.
- Save a copy before any destructive cleanup.
The embedded duplicate checker can inspect pasted CSV or TSV data by selected columns and return grouped counts and row indexes without changing the source sheet. Its row indexes refer to the submitted data; verify their relationship to sheet row numbers, especially if the pasted range starts below row 1 or includes a header.
When removing duplicates in Google shared sheets, coordinate with editors before cleanup. Rows can change while a report is being reviewed, so recheck the relevant range immediately before removal. A saved copy gives reviewers a reference, but it does not merge later edits into the cleaned sheet. removing-duplicates-google-sheets-apps-script
Record and test a removal macro
Google Sheets can record a sequence of actions as a macro. Recording is useful when the same cleanup rule and range structure recur; it does not decide which conflicting record is correct.
- Make a copy of the spreadsheet and open the copy.
- Select the data range, including headers if present. Note which columns define a duplicate and which rows should be retained.
- Choose Extensions > Macros > Record macro. Choose absolute references if the recorded steps should target the same coordinates, or relative references if they should depend on the selected cell.
- With the intended range selected, choose Data > Data cleanup > Remove duplicates. Confirm the header option and comparison columns in the dialog, then remove duplicates.
- Save the recording, give the macro a name, and inspect the remaining rows against the saved copy and duplicate report.
- Test the macro on another disposable copy with representative duplicates, unique rows, blanks, and conflicting records before using it on working data. Authorize it if Google Sheets requests permission.
Remove duplicates keeps the first occurrence within the selected range and removes later matching rows. Sort the full range first if a specific record must come first, and verify the sort order before removal. If different groups require different retention decisions, resolve them manually instead of relying on one recorded sequence.
A recorded macro can be tied to a particular range or selection. Adding columns, moving data, or changing headers can make its recorded steps unsuitable; inspect the macro in Extensions > Macros > Manage macros and retest after structural changes. The read-only checker reports duplicates separately and does not run or create the macro. google-docs-duplicate-row
Export evidence
Preserve the duplicate report and a copy of the source data before cleanup. Record the selected range, key columns, normalization rule, review date, and retention rule alongside the results so another editor can understand why records matched.
The checker supports downloading its results for review. For a formula-based report, copy the group counts and relevant row identifiers to a separate sheet, then use File > Download to export an appropriate spreadsheet or CSV file. Reconcile the retained rows against that evidence after the macro runs; a group count alone cannot show whether the correct record survived.
FAQ
Does this page delete macro for removing duplicates in google sheets?
No, it returns a read-only duplicate report.
Run read-only duplicate check to inspect duplicate detection, grouping, and report export and export a controlled report without destructive cleanup.
Run read-only duplicate check to inspect duplicate detection, grouping, and report export and export a controlled report without destructive cleanup.
Run read-only duplicate check