-1

I'm currently working on a pre-filled sheet, that is made available on Google Drive, for users to keep track of their personal data. As there are too many users and the data being personal, they cannot edit the source file, hence the need for copy.

However, some cells contain formulas and/or data that may not be modified as this has been pre-set. As they copy the sheet, all existing protections in-place get dropped or reflect back to them as the'owner, rendering it useless.

After Googling I found out that Google does not have a default 'undo' function to run as a script. My thought would be to instead create a function onEdit() that would fetch the original value of said cell before edit, return a message saying the user can't edit the cell, and cancel the actual edit and/or revert the cell back to its initial value.

I understand I'd need to find a way to store the data before an edit, so that the script knows what to return. This part is however something I cannot seem to wrap my head around.

Any suggestions would be tremendously helpful!

Thomas
  • 1
  • 1

1 Answers1

1

Using onEdit(e) as Trigger, you have access to the event object which contains the attributes oldValue, value and range.

With range you can determine if that cell is "allowed" to be edited according to your use case.

oldValue as the name says, is the value before and value is the new input. Keep in mind that value will only be available if the range is a single cell.

You can find more information about onEdit(e) trigger here

Gustavo
  • 639
  • 2
  • 4