I am looking for a Google Sheets script that will delete anything after the first instance of a duplicate row but only search column B. I found the following script on here but it only addresses duplicate rows that are back to back. For example if cell B5, B7, and B15 all had the same content I would like it to deleted Row 7 and Row 15. Any help is much appreciated.
function removeDuplicates() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getLastRow();
var firstColumn = sheet.getRange(2, 2, rows, 1).getValues();
for (var i = rows; i >= 2; i--) {
if (firstColumn[i-1][0] == firstColumn[i-2][0]) {
sheet.deleteRow(i);
}
}
}
Best Answer
Try changing from
To