1
votes

I need to set formula to a range in A1Notation. The Error: TypeError: Cannot find function setFormula in object Range.

I want to find the last row of column F (continuos data), get the Row index then set formula from C1 to the last row. I figured out how to get the range. But I don't know why I can not set formula to that range.

ss.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
var lr = ss.getCurrentCell().getRowIndex();

var fillDownRange = ss.getRange(9, 3, lr-8).getA1Notation();
fillDownRange.setFormula('=$F$7')

Please help me out here. Thanks in advance

1
I fingure it out: i should add: ss.getRange(fillDownRange).setFormula('$F$7'). Thank you for reading - Nguyen Thi Lan Anh
or: var fillDownRange = ss.getRange(9, 3, lr-8); fillDownRange.setFormula('=$F$7'); - ziganotschka
@ziganotschka's code is more efficient, there's no point getting the range twice. - ross

1 Answers

0
votes
function runOne(){
  var ss=SpreadsheetApp.getActive().getActiveSheet();
  ss.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
  var lr=ss.getCurrentCell().getRowIndex();
  ss.getRange(9, 3, lr-8,1).setFormula('=$F$7');
}