I'm using below script to check if cell is non empty then protect it.


I want to also check if that non empty cell is unprotected then only protect it.

How to do that in below script ???

function onOpen() {
var range = SpreadsheetApp.getActiveSheet().getDataRange();
var values = range.getValues();
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] !== "") {
range.getCell(i + 1, j + 

closed as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Jamal Jan 12 at 14:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ For advice on how to adjust your code to make it work as intended, try Stackoverflow. This site is for refining code that is working as required. ...and remember to tab your code when you post a question. \$\endgroup\$ – mickmackusa Jan 12 at 13:11