'Google Sheets Apps Script - set all blank cells in a column to zero

I am a novice when it comes to macros or Google Sheets Apps Script. I'm trying to write a Google Sheets macro to reformat data periodically exported from a website. So far I've figured out most of it, but I'm getting stuck trying to find all blank cells in certain columns (ignoring the header row) and set them to zero. Here's what I have so far:

function _1() {
  var spreadsheet = SpreadsheetApp.getActive();
  var k = 2;
  var j = spreadsheet.getLastRow();
  var column = 10;
  for (var i = k; i = j; i++){
    cell = spreadsheet.getRange(i,column);
    if (cell.isBlank()) { 
      cell.setValue(0);
    }
  }
}

This returns the following error:

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

I believe this means the getRange function is expecting an input of A1 style cell location, but I'm not certain. I also don't know how to convert to one. Finally I'm not sure that the script will work once I've fixed this. Any help would be appreciated.



Solution 1:[1]

function zero() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const vs = sh.getRange(2, 10, sh.getLastRow() - 1).getValues();
  vs.forEach(e => {
    if (e[0] == '') {
      e[0] = 0;
    }
  });
  sh.getRange(2, 10, vs.length, 1).setValues(vs).setNumberFormat('0.#####');
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cooper