Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing Duplicate Rows if Data in Columns B-F are Identical

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help is appreciated. Thank you!

>Solution :

As the docs say, use

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading