0

Can you please help me with this script? I've tried to edit it to apply to multiple tabs the same as the original question. But I think something's amiss. :( Here's the original code and I want this formatting protection script to apply to Secondary2,3,4, etc.

    function onEdit(e){           //This is activated each time a modification happens in the sheet
   var tabs = [ 
      'Prek_K', 'G1', 'G2C', 'G2J', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'G10', 'G11', 'G12', 'Withdrawn' ];
  var ss = SpreadsheetApp.getActive()
    for (var i = 0; i < tabs.length; i++) {
  var sheet =ss.getActiveSheet()
  if(sheet.getSheetName() == tabs[i]){
  var entryRange = e.range
  var range  = sheet.getRange(1,entryRange.getColumn(),1,entryRange.getNumColumns())              //This will be you range to get the formatting from row "1" and corresponding column based on the column being edited
  Logger.log(entryRange.getA1Notation())
  range.copyFormatToRange(sheet, entryRange.getColumn(), entryRange.getNumColumns()+entryRange.getColumn()-1, entryRange.getRow(), entryRange.getNumRows()+entryRange.getRow()-1)
  Logger.log(entryRange.getColumn())
  if(entryRange.getColumn() == 1){                                 //This column value will not be allowed modified except for row 1 of that column
    if (entryRange.getRow() != 1){                                  //The columns in row "1" will be allowed to modified
    e.range.setValue((e.oldvalue == undefined? "": e.oldvalue))
    }
  }
  }
}
}
  • I've sorted it. It works now, if anyone needs it. What it does is, it takes the first row as a template and applies its format to all rows in the defined range. – Vlad Pyagay Apr 12 at 7:10

Your Answer

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.