0

I'm trying to make a script that automatically change the background color of cells depending on which user edits it. I currently have this code but it doesn't do anything. We need to know which user edits or creates a new entry.

I just need the cells in the first column to change background color. This is for a Data base I'm working with 4 other people

function checkEdits() { var s = SpreadsheetApp.getActiveSheet(); //checks that we're on the correct sheet if (s.getName() == "Sheet1") { var r = s.getActiveCell(); //checks the column if (r.getColumn() == 1) { var email = r.Session.getActiveUser().getEmail(); if (email == "[email protected]") { r.setBackground('#dbbf94'); } if (mail == "[email protected]") { r.setBackground('#94dbab'); } if (mail == "[email protected]") { r.setBackground('#a2bfdf'); } if (mail == "[email protected]") { r.setBackground('#cf9ce5'); } if (mail == "[email protected]") { r.setBackground('#dfa2b1'); } } } } 

I expect that when a user edit a cell un Column A, the same cell changes its background to the specific user color

0

1 Answer 1

-1

You may want to try this.

function onEdit(e){ if (e.range.getSheet().getSheetId() == e.source.getSheetByName("Sheet1").getSheetId() && e.range.getColumn() == 1.0){ switch (e.user){ case "[email protected]": e.range.setBackground('#dbbf94'); break; case "[email protected]": e.range.setBackground('#94dbab'); break; case "[email protected]": e.range.setBackground('#a2bfdf'); break; case "[email protected]": e.range.setBackground('#cf9ce5'); break; case "[email protected]": e.range.setBackground('#dfa2b1'); break; default: e.range.setBackground('white'); } } } 
Sign up to request clarification or add additional context in comments.

2 Comments

just to be clear, this function doesn't need (can't) be run as a standalone function, it will automatically run when a change is made to your sheet. So you rather need to make changes to the first column of "Sheet1" and see the color change.
This doesn't work with @gmail.com accounts. It might work with Google Workspace accounts if the editors belong to the same domain as the spreadsheet owner.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.