0

I am new to Google Apps Script and I don't know how to do some codes. I have two spreadsheets, 1 for the admin and 1 for the client. Every time the admin will update the cells the client side must be updated also. However, only the data in the cells are copied but not the backgrounds in it. Here are the screenshots for better understanding:

Admin Side

Client Side

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 2
    Welcome to StackOverFlow please take this opportunity to take the [tour] and learn how to [ask] and provide [mcve]. And if you receive an answer that helps you to resolve your problem please check it off so that everyone can see that the problem is resolved. Generally, we like to see the code that you have are having a problem with and a description of what you have tried. If you successfully integrate all of these suggestions into your question then your much more likely to get a quick resolution to your problem. – Cooper Mar 10 '19 at 17:10
  • Hi sir, thanks for taking a quick look to my problem. I appreciate it but the thing is I don't know how to start coding. –  Mar 11 '19 at 02:39

1 Answers1

0

Copy value and background from Admin to Client

This requires an installable onEdit(e) trigger. You will also need the id of the client spreadsheet. Note you cannot run this from the Script Editor unless you do it from another function that supplies the event object. See this example.

function updateClient(e) {
  var ss=SpreadsheetApp.openById('ClientSideSpreadsheetId');//You need to provide id here.  You cannot pass other parameters to this function because it a trigger.
  var sh=ss.getSheetByName(e.range.getSheet().getName());
  var rg=sh.getRange(e.range.rowStart,e.range.columnStart);
  rg.setValue(e.value);
  rg.setBackground(e.range.getBackground());
}

I tested this on my account and it works. I suspect that you'll have trouble getting it to run so read the answer in the link I provided thoroughly before telling me that it doesn't work.

This is what the event object looks like:

{"authMode":{},"range":{"columnStart":3,"rowStart":18,"rowEnd":18,"columnEnd":3},"source":{},"user":{"nickname":"nickname","email":"email@email.com"},"triggerUid":"123456","value":"3"}
Cooper
  • 59,616
  • 6
  • 23
  • 54