Pages

Wednesday, 3 July 2019

Change Google Sheet cell colour on edit

The following Google Apps Script is designed to automatically change the active cell background colour in a Google Sheet when a user edits the content of it. This was created as I was learning about the various ways to deal with somebody 'signing' a spreadsheet by entering their name into a cell. By changing the colour it would be easier for somebody to see the change when glancing at multiple spreadsheets.
Screenshot of cell colour change
Screenshot of cell colour change

We make use of the 'onEdit(e)' trigger to achieve this task which takes an 'event object' - e - that is passed to the function so we can determine which cell has been edited. This means we do not require a separate project trigger to be created.
var cell = e.range;
So from here we now have the active cell that was modified by the user allowing us to perform any number of tasks with it. In this instance we will be changing the background colour of the cell.
cell.setBackground('#faaf00');
Now once the user edits a cell it will change to a yellow colour.

Change Google Sheet cell colour on edit.xlsx

No comments:

Post a Comment