How can I change whole rows background color of active cell in google script?
SpreadsheetApp.getActiveRange().setBackgroundRGB(224, 102, 102)
The code above only changes active cells background color. But I need to change row of active cells background.
Class Range and Class Sheet have methods you can use to pick the row that the cell is in. This is similar to the technique used in this answer.
SpreadsheetApp.getActiveSheet().getRange(SpreadsheetApp.getActiveRange().getRow(),1,1,SpreadsheetApp.getActiveSheet().getLastColumn()).setBackgroundRGB(224, 102, 102);
This does the same thing, broken down into easier-to-read lines:
var sheet = SpreadsheetApp.getActiveSheet();
var activeRange = SpreadsheetApp.getActiveRange();
var changeRange = sheet.getRange(activeRange.getRow(),1,1,sheet.getLastColumn());
changeRange.setBackgroundRGB(224, 102, 102);
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