Chapter 1 Recording and running macros ・ MISSION 2
Mission 2: Record a macro (absolute references)
Task
Start recording with "Extensions" → "Macros" → "Record macro", type "Total" in A6 and make it bold. After saving, run the recorded macro from "Extensions" → "Macros" to check that it repeats the same actions.
For practice, the table goes back to its starting state every time before the code runs (a real spreadsheet doesn't go back. Script changes can sometimes be undone with Ctrl+Z, but not all at once).
Chapter 1 ・ MISSION 2
Record a macro (absolute references)
Start recording with "Extensions" → "Macros" → "Record macro", type "Total" in A6 and make it bold. After saving, run the recorded macro from "Extensions" → "Macros" to check that it repeats the same actions.
Reading the code
- spreadsheet.getRange('A6').activate();
- Selects A6. With absolute references, selecting is saved as an address.
- spreadsheet.getCurrentCell().setValue('Total');
- Puts "Total" in the selected cell (getCurrentCell).
- spreadsheet.getActiveRangeList().setFontWeight('bold');
- Makes the selected range bold. Ctrl+B becomes this line.
Each action while recording becomes one line of Apps Script. With absolute references, selecting a cell is saved as an address such as getRange('A6'), so it writes to the same place whichever cell is selected.
How to get started with GAS and common code are covered in an article.What is GAS? Getting started and common code
The code you write runs in an isolated place inside this page. It can't reach outside the page or other sites.
* This is a simulation of how Google Sheets and Apps Script behave and may differ in some ways from the real thing.
* Google Sheets is a trademark of Google LLC. This site is not affiliated with Google.