I need a script that formats the cells in column A bold, but only the cells that contain the word 'Hello'. Also, a similar script that makes the cells containing 'hello' aligned center and one that also formats underlined. You can't conditionally format bold or align or underline in Google Sheets, so I will need a script.
I think it's something like this but I don't know what the last line would be.
function formatBold() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet1');
var values = s.getDataRange().getValues();
for( var row = values.length -1; row >= 0; --row )
if (values[row][0] == 'Hello')
};
Does anyone know how to complete this script or if there is a better script for the job?
This is pretty well documented in the documentation, you can simply use
// row+1 because array are 0 indexed while range is 1 indexed
s.getRange(row+1,1).setFontWeight("bold");
The other "styles" are available in the same documentation and apply the same way.
EDIT : following your comment, if you want to reset all cells of a specified range to 'normal font' just set to 'normal' in a loop for example. Please have a look at this example sheet (make a copy)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With