Question Details

No question body available.

Tags

google-sheets google-apps-script

Answers (2)

January 10, 2026 Score: 1 Rep: 39,623 Quality: Low Completeness: 90%

If you will be using the function as a custom function, add return HomeScore before the last }.

If you will be running it from another place, your script should first grab the destination range, then use setValue(value), i.e.,

PossessionSim.getRange("A1").setValue(HomeScore);

References

January 10, 2026 Score: 0 Rep: 22,095 Quality: Low Completeness: 70%

take a value from a cell (B21, which is the sum of B11:B20) and add that value to the existing value in cell B4

Use Range.setValue(), like this:

function incrementHomeScore() {
  const sheet = SpreadsheetApp.getActive().getSheetByName('Possession Simulation');
  const targetCell = sheet.getRange('B4');
  const oldValue = Number(targetCell.getValue()) || 0;
  const increment = Number(sheet.getRange('B21').getValue()) || 0;
  targetCell.setValue(oldValue + increment);
}

See Range.setValue().