vendredi 21 août 2015

Google Script that edits every row that has a certain value in it

I'm trying to write a script that, when run, searches for the value 'Yes' in the S column and if it finds it, it copies the columns J:M and pastes them into I:L. For example if there is a 'Yes' in S5, then it takes J5:M5 and pastes it into I5:L5. And it does this for each row that has 'Yes' in column S. At the moment, when I run this it moves random rows, not the rows that have 'Yes' in column S. Any ideas why?

Here's my current code;

function updateyear() {

var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange();
var numRows = data.getNumRows();
var values = data.getValues();

 for (var row = 3; row <= numRows - 1; row++) {
var str = values[row][18]; 
if (str.indexOf("Yes") >-1) { 
  var range = sheet.getRange(row, 10, 1, 4); 
  var val = range.getValues();
  range.clearContent(); 
  sheet.getRange(row, 9, val.length, val[0].length).setValues(val); 
  }
 }
}

Aucun commentaire:

Enregistrer un commentaire