Reputation: 357
I have a Google sheet where one column contains values. It is column number 10 in the sheet and I need the cells of that column to change color if the cell contains the word 'Declined'. I am having issues. Here is what I have tried
var statusColumn = sheet.getRange(10, sheet.getLastRow()-1);
var oValues = statusColumn.getValues();
for (var i = 0; i < oValues.length; i++) {
if (oValues[i] == 'Declined'){
sheet.getRange().setBackGroundColor('yellow');
}
}
This does not work. Any help?
Upvotes: 1
Views: 241
Reputation: 201378
It is column number 10 in the sheet
, you want to search the values of the column "J".Declined
.If my understanding is correct, how about this modification?
var statusColumn = sheet.getRange(10, sheet.getLastRow()-1)
is one cell. In your situation, you can use getRange(row, column, numRows)
.setBackground(color)
instead of setBackGroundColor()
.var statusColumn = sheet.getRange(1, 10, sheet.getLastRow(), 1); // For example, if you want to retrieve the values from row 2, please modify to sheet.getRange(2, 10, sheet.getLastRow(), 1);
var oValues = statusColumn.getValues();
for (var i = 0; i < oValues.length; i++) {
if (oValues[i][0] == 'Declined'){
sheet.getRange(i + 1, 10).setBackground('yellow');
}
}
1
was used.If I misunderstood your question and this was not the result you want, I apologize. At that time, can you provide a sample Spreadsheet including what you want? I would like to modify the script.
Upvotes: 1