Chapter 1 Recording and running macros ・ MISSION 4

Mission 4: Edit recorded code

📋 Mission list

Task

You opened the recorded macro in the Apps Script editor. Fill in the blanks so that the header A1:C1 gets a pale yellow (#fff2cc) background, then click ▷ Run.

Office supply order sheet - Google Sheets
Office supply order sheet

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).

Apps ScriptRecorded macros (Office supply order sheet)Deploy ▾
/** @OnlyCurrentDoc */
function myFunction() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('').activate();
spreadsheet.getActiveRangeList().('#fff2cc');
};
Ctrl+S: save · Ctrl+R: run (editor) · F5: reopen

Chapter 1 ・ MISSION 4

Edit recorded code

You opened the recorded macro in the Apps Script editor. Fill in the blanks so that the header A1:C1 gets a pale yellow (#fff2cc) background, then click ▷ Run.

Now
Goal

Reading the code

spreadsheet.getRange('A1:C1').activate();
Selects A1 to C1. Change what is inside ' ' to change the target.
spreadsheet.getActiveRangeList().setBackground('#fff2cc');
Sets the background color of the selected range to #fff2cc (pale yellow).

You can reuse recorded code for other actions just by changing the addresses and methods. You can also skip the selection and write it as one line: spreadsheet.getRange('A1:C1').setBackground('#fff2cc');

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.