I have a Google Sheet with two tabs that I want to check rows and delete duplicates from. However, the requirement for both is slightly different.
On tab submittedMatches I have data imported from a Google Form into columns A:C where a script on form submit then grabs data from an API and populates D:J and finally, K:M has a custom formula inserted via a script. The range of data being A2:M
The problem I am having is that a) I'm new to all of this, and b) when I try to remove duplicates (people can submit the same thing twice from the form) the only solution I have found copies all the rows, removes the duplicates and pastes the unique rows again so I lose the formulas.
I have the script checking columns B (this just has a letter from A-Z) and C (a unique ID) for duplicates, e.g., If row 2 and 3 have an "A" in column B and "123456" in column C, then this is a duplicate. For reference, this is what I had working:
function removeDuplicates() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var newData = [];
for (var i in data) {
var row = data[i];
var duplicate = false;
for (var j in newData) {
if(row[2] == newData[j][2] && row[3] == newData[j][3]){
duplicate = true;
}
}
if (!duplicate) {
newData.push(row);
}
}
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}
What I need to happen is the script check for the duplicate rows based on data in columns B and C and remove them, but the formula in K:M must be preserved. Either by just removing the data from A:J or by another method.
Additionally, I'm assuming I need to make sure this is only run on the tab 'submittedMatches' and not other tabs on the sheet.