Office Scripts automate Excel with TypeScript. You write them in the Code Editor: Automate > New Script. They run in Excel for the web and in recent desktop versions, and Power Automate can run them on a schedule, which VBA can't do.
Every script has one function, main, and Excel passes the workbook in:
function main(workbook: ExcelScript.Workbook) { ... }
From the workbook you get a worksheet, with getActiveWorksheet() or by name with getWorksheet("Orders"). From the sheet you get a range with getRange("G1"), then call setValue, setFormula or setValues. console.log writes to the Output pane.
getWorksheet returns undefined when no sheet has that name, and the next call then stops the script. Check for that when a sheet may be missing. setValues takes a two-dimensional array: one inner array per row, even for a single row.
This practice Code Editor runs your script against the workbook beside it. It removes the types and reports syntax errors by line, but it doesn't type-check the rest, run async code or make network calls.
The script gets the sheet by name and writes a formula, so the total keeps following the data.