script to insert formula

Asked

Viewed 330 times

1

Well, I’ve come up with a script to check if a column contains a formula, and if it doesn’t, it inserts. I’m doing this because every time I fill out a form, the formula that was before in the cell goes missing. So, the script will run hourly, check if the formula has been deleted, and if so, it inserts it again. Well, me script and this? However, it is not working, although do not accuse any error, the formula does not appear in the column as it should. NOTE: if I put double quotes, it gives an error of: ~Missing ; before the declaration. (line 13, file "inserts"). row 13 and: term = "=IF(COUNTA(E4)=0;"";E4-TODAY())"; So, I left even simple quotes.

function myFunction() {

  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 0;  // First row of data to process
  var numRows = sheet.getLastRow();
  var lastCol = sheet.getLastColumn();
  var dataRange = sheet.getRange(2, 1, numRows-startRow,lastCol).getValues();  //Get all values except the header rows


  for (var i=0;i<numRows-startRow;i++){ 
  var prazo = dataRange[i][8];
    if (prazo == '') {
     prazo = '=IF(COUNTA(E4)=0;"";E4-TODAY())'; 

    }
  }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.