I'm trying to set a formula in Google Sheet from Google App Script.
Here's the illustration of the Spreadsheet:
I also tried to make the code but I don't know how to loop it so for every values added to cell range 'A3:F' will automatically SUM it to the Total column (column G). Could you show me how to loop it? Your response will be appreciated :)
function onEdit(e){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet1');
var cell = s.getRange("G3");
cell.setFormula("=SUM((A3/100)*D3)+((B3/100)*E3)+((C3/100)*F3)");
}
EDIT
Here's the updated code that works for me:
function onEdit(e){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet1');
const cell = s.getRange(3, 7, s.getLastRow());
cell.setFormula("=SUM((A3/100)*D3)+((B3/100)*E3)+((C3/100)*F3)");
}