I would like to automatically protect columns where a header row contains a date based on whether the date in the google sheet app script
Here is a screenshot of the sheet: .
.
I have tried and created a script that can work but it showing an error in getting last column please suggest if any edit needs to be done I am also attaching the screen shot of the error please check it out also
Script -
function Lock_Cells() {
  var ss= SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Sheet 1'); 
  var lastcolum = sheet.getLastColumn();
for (var i = 3; i <= lastcolum; i++){
 var today = sheet.getRange(0,3).getValue();
  var Check_date = sheet.getRange(5,i).getValue();
  if (Check_date < today){
     var Lock_Range = sheet.getRange(5,i,50);
     var protection = sheet.getRange(Lock_Range).protect();
     var description = "colum " + i;                 
     protection.setDescription(description);
     var eds = protection.getEditors();
     protection.removeEditors(eds);
  }}}
Screenshot of error - 
Thanks to you that problem is solved and now the sheet is showing the last column but now when I run the function it is showing an error and is not completing the script I have attached the screenshot of the error and the error showing is -
Error Exception: The starting row of the range is too small. Lock_Cells @ Code.gs:11
Screenshot https://i.stack.imgur.com/fDK9g.png
 
    