0

I am trying to delete rows in bulk which has values as web links starting with "www." There are 1000+ such entries in my Google Spreadsheet which starts with "https://www." and "www."

I wish to delete only those starting with "www." and I tried this code in GAS.I'm pretty naive to GAS. Unfortunately I'm missing out on some part of code due to which it is deleting all instances which has "www."

Below I have pasted the code snippet:

function deleteRows() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var values = rows.getValues();
  var toDelete = [];
  var re = new RegExp('www.'); 

  for (var row = 0; row < values.length; row++) { 
    for(var column = 0;column<values[row].length;column++){ 
      if (re.exec(values[row][column])){
        toDelete.push(row); 
      } 
    } 
  }

  for(var deleteRow = toDelete.length-1; deleteRow >= 0;deleteRow--){
    sheet.deleteRow(toDelete[deleteRow]+1);
  }

Also I did try out this which worked partially after tweaking. Delete row in Google Sheets if certain "word" is found in cell

pnuts
  • 58,317
  • 11
  • 87
  • 139

0 Answers0