Llama Bean
Llama Bean

Reputation: 1

How do you make a script in Google Sheets to delete certain values in a column?

I'm trying to make a script to help out co-workers that deletes stuff on a google sheet where if column c is a certain phrase, but cant seem to get the DataRange to work thus the script won't run, and I don't use JavaScript ever so I'm not sure on how I'm supposed to set it up.

Upvotes: 0

Views: 19

Answers (1)

Cooper
Cooper

Reputation: 64120

function delRowIfColumnCEqualACertainPhrase() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet1');
  const sr = 2;//data start row
  const vs = sh.getRange(sr, 1, sh.getLastRow() - sr + 1, sh.getLastColumn()).getDisplayValues();
  let d = 0;
  vs.forEach((r, i) => {
    if (r[2] == 'A certain phrase') {
      sh.deleteRows(i + sr - d++);//current row is deleted if column c = 'A certain phrase'
    }
  });
}

Upvotes: 1

Related Questions