Automate tasks with macros

" "

Tips

Save time by automating repetitive tasks with macros in Google Sheets. Say you need to format new data imports or build the same chart across multiple sheets of quarterly data. Repeating the same steps manually can take hours. Use a Sheets macro to record these actions and easily use them again without having to write code.

Create and run a macro" "

  1. In Sheets, open a spreadsheet.
  2. At the top, click Toolsand thenMacrosand thenRecord macro.
  3. At the bottom, select the type of cell reference to use:
    • Use absolute references—When you run the macro, it will only do tasks on the exact cells you select. For example, if you start in cell B1 (recording starts when you place your cursor) and then click cell D1 and bold it, the macro will always bold cell D1.
    • Use relative references—When you run the macro, it will do tasks on the cell you select and work you do on other cells. For example, if you start in cell B1 and add a formula and then click cell D1 and bold it, the macro will always add the formula and then move 2 cells to the right and bold that cell.
  4. Complete the task you want to record. When you’re done, click Save.
  5. Name the macro.
  6. (Optional) Create a custom shortcut for the macro.
  7. Click Save.
    Note: When you create a macro in Google Sheets, a script is created by Google Apps Script. To edit it, at the top, click Toolsand thenScript editor.
  8. Click Toolsand thenMacrosand thenyour macro to run a macro.

Edit or remove a macro" "

  1. In Sheets, open a spreadsheet.
  2. At the top, click Toolsand thenMacrosand thenManage macros.
  3. Next to a macro, click MoreMoreand thenEdit script or Remove.
  4. When you’re done, click Update.

Create custom functions" "

  1. In Google Drive, open the spreadsheet for your custom function.
  2. At the top of the spreadsheet, click Tools > Script editor. If you see a welcome screen, click Blank Project.
  3. Add the code for your custom function or macros.
  4. Click Fileand thenSave and enter a new project name.
  5. Click OK.
  6. In Google Sheets, refresh the spreadsheet that contains your custom function to see your changes.

See sample Sheets functions you can use.

Was this helpful?
How can we improve it?