Home > Software design >  Removing Duplicate Rows if Data in Columns B-F are Identical
Removing Duplicate Rows if Data in Columns B-F are Identical

Time:06-24

So for this problem I have data in columns A-G and I need to remove entire rows with duplicate information in rows B-F:

function urlsToSheets(){
    importData("https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv", "Pavement Condition");
}


function importData(url, sheetName) {
    let requiredColumns;
      if (url == "https://hub.arcgis.com/datasets/d3cd48afaacd4913b923fd98c6591276_36.csv"){
        requiredColumns = [0, 3, 11, 12, 13, 14, 30]; 
    const res = UrlFetchApp.fetch(url);
    const ar = Utilities.parseCsv(res.getContentText());
    const values = ar.map(r => requiredColumns.map(i => r[i]));
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    sheet.clear();
    sheet.getRange(1, 1, values.length, values[0].length).setValues(values);
    // sheet.getDataRange().removeDuplicates("B:B","F:F");
}

This script is actually written for 5 URLs and 5 Separate sheets, but I've simplified it for one URL/sheet in this example.

I know my syntax for removing duplicates is incorrect, but I'm not sure if this is a one-line type of problem or if I'll need to use a loop of some kind.

Any help is appreciated. Thank you!

CodePudding user response:

As the docs say, use

sheet
    .getRange(1, 1, values.length, values[0].length)
    .setValues(values)
    .removeDuplicates([/*B*/2,3,4,5,6/*F*/])
  • Related