Duplicate detection, grouping, and report export
Google Script Duplicate Sheet And Rename
Use a read-only duplicate check for google script duplicate sheet and rename 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.
To duplicate a sheet and rename it with Google Apps Script, call copyTo() on the source sheet and setName() on the copy. This changes the spreadsheet; a read-only duplicate check instead finds repeated values without creating or renaming a sheet.
Duplicate a sheet and rename the copy
Open the spreadsheet, choose Extensions > Apps Script, and add the following function. Replace Source and Source Copy with the names you need.
function duplicateAndRenameSheet() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const source = spreadsheet.getSheetByName('Source');
const newName = 'Source Copy';
if (!source) {
throw new Error('Source sheet not found.');
}
if (spreadsheet.getSheetByName(newName)) {
throw new Error('A sheet with the requested name already exists.');
}
const copy = source.copyTo(spreadsheet);
copy.setName(newName);
}
Save the project, select duplicateAndRenameSheet, and run it. Authorize the script if prompted, then return to the spreadsheet and check the new tab. The source tab remains in place; the script adds a copy to the same spreadsheet.
The name check prevents an attempted rename to an existing tab name. Choose a valid, unused name before each run. If copying succeeds but renaming fails, inspect the spreadsheet for the newly created copy before trying again; the two operations are separate.
A copied sheet can contain duplicate values because its source contains them. A repeated tab is not the same problem as repeated records within a sheet. Check the data separately if the goal is to identify duplicate values rather than make a backup or working copy.
Check repeated values without changing source data
For a read-only review, decide which columns define a match. A single email address might identify a repeated contact; an order ID plus product code might be needed to distinguish order lines. Select only the relevant data set and keep the header row separate from records.
The embedded duplicate checker accepts pasted TSV or CSV data and lets you choose the key columns. Its report groups matches and provides counts and row-level evidence for export; the check does not edit the source sheet.
Normalize the selected values
Differences in capitalization or surrounding spaces can split values that represent the same key. In an empty helper column, enter this in B2 when the original key is in A2: google-script-find-duplicate-sheets
=IF(A2="","",LOWER(TRIM(A2)))
Fill the formula down to create a normalized key for each populated row. TRIM removes leading and trailing spaces and reduces repeated ordinary spaces; LOWER makes text lowercase. The formula leaves column A unchanged, but it writes results to the helper column, so use an empty column or a separate working sheet.
Normalization is a matching rule, not proof that records are identical. For example, treating Acme and acme as the same may suit a company-name review but not a case-sensitive identifier. Inspect unusual whitespace, formatting, and missing data before relying on group counts.
Group and count matches
With normalized keys in B2:B100, place this formula in another empty area:
=QUERY(B2:B100,"select B, count(B) where B is not null group by B having count(B) > 1 label B 'Key', count(B) 'Count'",0)Use the checker when you need to confirm duplicates before copying, renaming, or deleting rows in Google Sheets.
Each returned row shows a repeated key and its count within the specified range. A count of three means three populated rows share that normalized key; it does not identify which record should be kept. Expand the range when the data set grows, and keep the result area clear so the report can expand. does-not-equal-in-google-sheets
To identify individual rows, put this formula in C2 and fill down alongside the data:
=IF(B2="","",IF(COUNTIF($B$2:$B$100,B2)>1,"Duplicate","Unique"))
The fixed range stays anchored as the relative reference B2 moves to each row. Filter column C for Duplicate to inspect all members of each group, including the first occurrence. This method checks one key column; for a multi-column key, count matching columns together or construct a key whose separators cannot be confused with values in the data.
For example, when customer ID is in A and order ID is in B, this formula marks repeated pairs without joining text: not-equal-in-google-sheets
=IF(OR(A2="",B2=""),"",IF(COUNTIFS($A$2:$A$100,A2,$B$2:$B$100,B2)>1,"Duplicate pair","Unique pair"))
It excludes rows missing either component. If blank values are meaningful in your data, define a different rule instead of silently treating those rows as unique.
Inspect the report for google script duplicate sheet and rename
Compare the reported counts with the source rows before copying, renaming, or cleaning up a sheet. Check that the selected range includes every intended record and excludes the header row. A partial range can make a repeated value appear unique.
Use row indexes to locate each match, and confirm whether they refer to positions in pasted data or rows in the spreadsheet. If the pasted selection starts below row 1 or excludes rows, reconcile those positions with the source before taking action. Sort or filter only when you can still identify the original records.
The Google Sheets not-equal operator <> helps compare two cells on the same row: does-not-equal-sign-google-sheets
=IF(A2<>B2,"Different","Same")
Here, <> means does not equal; it compares A2 with B2, not every value across two ranges. A Different result alone does not establish that a value is missing from another sheet. Check blanks and the intended comparison scope before interpreting results.
Export evidence
Keep the group counts, matching keys, and source row references together when sharing findings. If you use the embedded check, download its report and verify that its row references can be mapped back to the original selection. Avoid including unrelated columns when the key and relevant context are enough for review.
Download the report to keep grouped counts, keys, and row references together when sharing your findings.Record the sheet name, checked range, selected key columns, and normalization rule with the evidence. Those details explain why two rows were grouped and make the check easier to repeat. Neither a duplicate report nor a copied tab decides which record is correct; review the underlying rows before any deletion or other cleanup.
FAQ
Does this page delete google script duplicate sheet and rename?
No, it returns a read-only duplicate report.
How do I use the check?
Paste data for google script duplicate sheet and rename; select the key scope; inspect grouped counts, row indexes, and exportable evidence.
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