Using Google Sheets macro to populate blank cells in a given column with a default value

312 views Asked by At

I would like to create a function for a Google Spreadsheet that will iterate through the rows in column L and populate blank cells with a default date. I get the following error:

Exception: The parameters (String,number,number,number) don't match the method signature for SpreadsheetApp.Spreadsheet.getRange.

Not sure why i is being considered a string.

function SetDateWhereBlank() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getActiveSheet();
  var defaultDate = new Date(2021,11,31);
  var startRow = 2;
  var lastRow = sheet.getLastRow();
  var column = 12;

  for (var i = startRow; i <= lastRow; i++) {
    // starting at row 2, if the value in column L is blank, populate the cell with the default date
    cell = spreadsheet.getRange(i,column,lastRow-1,1);

    if (cell.isBlank()) { 
      cell.setValue(defaultDate);
    }

  }
};
0

There are 0 answers