The following function colours the whole cell when textToFind is found (within the range C5:C23):
function findAndSetBackgroundColor(textToFind, format){
//Find cells that contain "ddd"
//let ranges = SpreadsheetApp.getActive()
let ranges = SpreadsheetApp.getActive().getRange('C5:C23')
.createTextFinder(textToFind)
.matchEntireCell(false)
.matchCase(false)
.matchFormulaText(false)
.ignoreDiacritics(true)
.findAll();
//Set the background colors of those cells to yellow.
ranges.forEach(function (range) {
range.setTextStyle(format);
});
}
Imagine we have on the range C5:C23:
| A header | Another header |
|---|---|
| First thing | row |
| Second thing | row |
As matchEntireCell is set to false, if textToFind is Second, then the whole cell Second thing will be formatted according with the param format
But I'd like to format the word found only, not the whole cell.
How to do it?