function colorCells() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName('Sheet1');//replace with your tab name
var range = ws.getRange('G6:G9');//replace with your pivot table column range. The below code assumes it is all in a single column
var data = range.getDisplayValues();
//loop through each cell
for (var i = 0; i < data.length; i++) {
// console.log(data[i][0])
var dataLen = data[i][0].length;
var end = 0;
var textColor = ""
if (data[i][0].indexOf('No') > 1) {
end = dataLen - 2;
textColor = "red"
}
if (data[i][0].indexOf('Yes') > 1) {
end = dataLen - 3
textColor = "green"
}
//set the cell color to red or green
var newColor = SpreadsheetApp.newTextStyle()
.setForegroundColor(textColor)
.build();
var richText1 = SpreadsheetApp.newRichTextValue()
.setText(data[i][0])
.setTextStyle(0, dataLen, newColor)
.build();
range.getCell(i+1,1).setRichTextValue(richText1);
//set front portion of cell content back to black
var black = SpreadsheetApp.newTextStyle()
.setForegroundColor('black')
.build();
var richText2 = SpreadsheetApp.newRichTextValue()
.setText(data[i][0])
.setTextStyle(0, end, black)
.build();
range.getCell(i+1,1).setRichTextValue(richText2);
}
}