Google-sheets – Script that adds new row to multiple sheets in Google Spreadsheets

google sheetsgoogle-apps-script

I want to add a script in Google Spreadsheets that adds new row on the second line of every sheet within a Google Spreadsheet that contains multiple spreadsheets.

This will need to happen every day.

Best Answer

Try this code:

function AddRow() {
  //gets the spreadsheet which it's bound to
  var ssheet = SpreadsheetApp.getActiveSpreadsheet();  

  //gets all sheets in this spreadsheet
  var sheet = ssheet.getSheets();                      

  //browses all the sheets, until "i" is larger than the number of sheets
  for (var i = 0; i < sheet.length; i++)               
  {
    //adds to the actual sheet a row AFTER the first row
    sheet[i].insertRowAfter(1);                        
  }
}

and trigger it on a daily basis (like on 1 a.m.)