GAS : setFormula parenthesis or quotes missing?

2019-09-14 21:41发布

问题:

If I want to put L2 = M2 , this works :

for (var j = 2; j<=sheetold.getLastRow(); j++){

sheetold.getRange(["L"]+[(j)]).setFormula('=["M"]+[(j)]');

But if I want the following L2 = (M2/P2), I am blocked (possibly some parenthesis or quotes misplaced on my part ??) :

sheetold.getRange(["L"]+[(j)]).setFormula('=["M"]+[(j)]/["P"]+[(j)]');

Thanks in advance ;)

回答1:

You don't need so many square brackets "[]" or parentheses.

Try this:

for (var j = 2; j<=sheetold.getLastRow(); j++){
  sheetold.getRange("L"+j).setFormula('=(M'+j+'\/P'+j+')'); }