Using google apps script and spreadsheet, I have been trying to do a simple thing but can\'t figure out the problem. I have a sheet, with a blank column and a column with te
function myFunction() {
//Variable to keep track of the sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//Start at row 1, end at the last row of the spreadsheet
for(var i=1;i<sheet.getLastRow();i++){
var value = sheet.getRange(i, 1).getValue();
//Compare the value of the cell to 'xyz', if it is then set column 4 for that row to "Yes"
if(value == 'xyz'){
sheet.setActiveRange(sheet.getRange(i, 4)).setValue('Yes');
}
}
}
This is a possible simple script that does what you need. (If your sheet contains formulas or custom function then it should be modified to take it into account)
function test(){
var sh = SpreadsheetApp.getActiveSheet();
var data = sh.getDataRange().getValues(); // read all data in the sheet
for(n=0;n<data.length;++n){ // iterate row by row and examine data in column A
if(data[n][0].toString().match('xyz')=='xyz'){
// if column A contains 'xyz' then set value in index [5] (is column F)
data[n][5] = 'YES'
};
}
Logger.log(data)
sh.getRange(1,1,data.length,data[0].length).setValues(data); // write back to the sheet
}