Home > Net >  How to protect a Google sheet: script that prevents adding rows
How to protect a Google sheet: script that prevents adding rows

Time:11-16

I have a google sheet that is protected from ordinary users.

Elevated users can edit the sheet but I want to prevent the adding of rows or columns because the sheet size is predefined.

So protection of the sheet is not an option, I want to have a way where a user other than myself cannot click the add rows button or insert rows or columns. If it is not possible to avoid this, then they should be removed immediately and a warning message should pop up.

Thank you for looking at my request.

CodePudding user response:

You don't need to protect an entire sheet to achieve your goal. You just need to protect one full row and one full column. For instance, it makes sense to choose the header row for protection. Then choose any full column that others will not ever need to modify (or add a column, protect that blank column, and then hide it). Grant editing permission only to yourself for that one row and one column.

This will allow others to edit any other editable portions of the sheet. But if they try to add or delete columns or rows, they won't be able to, because it would violate the protections set on your chosen single full-row or full-column above.

CodePudding user response:

Follow these step to achieve the desired goal :

  1. Create an Installable Trigger that can catch the insertion of rows and columns. enter image description here

    Demo:

    Column:

    enter image description here

    Row:

    enter image description here

    References:

  • Related