1

I have a script that should change the background color of a cell depending on which user inputs data. It seems the script does not recognize other users but me (the sheet owner), so when someone else inputs data the cell changes color but only to the one designated to my user.

I've tried a switch statement but nothing happened, so I used if and else if statements and at least got the cells to change colors. I program another cell to show the user name to check who is editing data, but only my username appears, other just don't show up.

function onEdit(e){ var s = SpreadsheetApp.getActiveSheet(); var cell = s.getActiveCell(); var user = Session.getActiveUser().getEmail(); if( s.getName() == "Sheet1" ) { if(cell.getColumn() == 2 ) { var colorCell = cell.offset(0,-1); var conCell = cell.offset(0,13); //Confirmation cell to see the user name conCell.setValue(user); var dateCell = cell.offset(0, 12); //this bit is to register the date of the edit if( dateCell.getValue() === '' ){ dateCell.setValue(new Date());} if (user = "[email protected]"){//only this user name seems to be recognized colorCell.setBackground('#dbbf94'); } else if (user = "[email protected]"){ colorCell.setBackground('#94dbab'); } else if (user = "[email protected]"){ colorCell.setBackground('#cf9ce5'); } } } } 

I want the background color to be specific for each user

3
  • I've been messing around with the code and change the order of the user and the color changed. That means The code is executing just until the first if statement related to background color. Has anyone any idea of why could that be? Commented Aug 20, 2019 at 23:10
  • 1
    duplicate of stackoverflow.com/q/57577388/5851272 ? Commented Aug 21, 2019 at 8:18
  • The code has syntax errors like using = instead of == or ===. Another non-trivial change is changing the function name to onEdit, which is a reserved name for an on edit simple trigger. Commented Aug 6 at 18:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.