I need to put a formula into a cell in each new row added to a Google Sheets. I have this working in VBA but not been able to build it correctly in Script. I loop through i rows until lastrow. In cell J, I want this formula inserted:
var Discount = '=IF(ISBLANK("F"+i,,IF(ISNUMBER(FIND("CM","B"+i)),IF("C"+i>"F"+i,150,0),0))';
I use this method to add the row:
var dtaCollect = ["","",StartDate,CustomerName,Monthly,"",Discount,LateFee,TotalPaid,Commission,Note,Referral];
target_sheet.appendRow(dtaCollect);
i++;
} else {
i++;
}
}
However, the formula is written exactly as above, without i
substituted with the iteration value. As a result I get #ERROR!
in the cell. I've tried INDIRECT
and concat
.
How can I fix this?