0

I have a problem with the .setUnprotectedRanges method

I want next ranges to be added in the loop. If the cell is not empty, another unlocked range should be added, which is in column 3. For example: In column 3, rows 5, 8 and 10 are not empty.

The code below works but is not flexible:

protection.setUnprotectedRanges (
                 [
                 spreadsheet.getRange ("A5: F5")
                 spreadsheet.getRange ("A8: F8")
                 spreadsheet.getRange ("A8: F8")
                 ])

This is my code:

function xx(){
var app = SpreadsheetApp;
var as = app.getActiveSpreadsheet().getActiveSheet()
var sr = 6
var lr = as.getRange(4,2).getValue()
var spreadsheet = SpreadsheetApp.getActive();
var aa = ''

  for (var i=sr;i<lr;i++){      
      if (as.getRange(i, 3).getValue() != ""){                   
                var allProtections = spreadsheet.getActiveSheet().getProtections(SpreadsheetApp.ProtectionType.SHEET);
                var protection = allProtections[0]
                protection.setUnprotectedRanges([])
                protection.setUnprotectedRanges(
                [
                spreadsheet.getRange("A" + i + ":B" + i)
                ])             
      }
   }
}

How can I make that different ranges will be added after a certain condition?

protection.setUnprotectedRanges (
                 [
                 spreadsheet.getRange ("A" + i + ": B" + i)
                 ])
New contributor
Ewelina Stawarz is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Welcome. I am funding your question a little hard to follow. I suggest that you add a some screenshots (or in-line tables) to show the spreadsheet layout, and also to show how a successful outcome would appear. – Tedinoz Mar 29 at 4:32

Your Answer

Ewelina Stawarz is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.