How to Automate Data Cleaning in Google Sheets

By Andrew Apell, creator of Flookup Data Wrangler. Updated

About the Author

Andrew Apell is the creator of Flookup Data Wrangler and has built data cleaning tools for Google Sheets since 2018. This guide draws on continued testing with Google Sheets users.
The Flookup features mentioned here are set out in the documentation.
Read Our Story for the background or contact the team with any questions about this post, including corrections, unclear steps or use cases we have not covered yet.

Key Takeaways

  • Macros automate repetitive sequences of UI interactions in Google Sheets.
  • You can record macros or write them manually in Apps Script.
  • Scheduling macros allows for fully automated, time-based data maintenance.
  • Combine macros with Flookup custom functions for fuzzy matching and standardisation in the sheet.

Streamlining Sheets with Macros

Quick Checklist

Step Action Why It Matters
1 Record a macro for a repeatable cleaning task Capturing repetitive steps once saves time on every future execution
2 Assign a keyboard shortcut for quick access Instant replay of cleaning steps reduces friction and speeds up workflow
3 Test the macro on a sample dataset Validate that recorded actions produce the expected output before scaling
4 Extend the macro with Apps Script for conditional logic Branching logic transforms a simple recorder macro into a robust automation
5 Schedule the script to run on a recurring basis Time-based triggers keep data clean without manual intervention

Automating repeated cleaning steps keeps the sequence consistent as datasets grow.

Google Sheets allows you to record macros, which duplicate a specific series of user interface interactions.

Once recorded, you can link a macro to a keyboard shortcut like ctrl+alt+Shift+Number.

This shortcut lets you quickly repeat data cleaning steps. You can also activate macros from the Extensions > Macros menu.

When you record a macro, Google Sheets automatically creates an Apps Script function that replicates your steps. This function is added to a file named macros.gs within a script project bound to your sheet.

Google Sheets also updates the script's manifest file, recording the macro's name and shortcut.

Since every macro is defined in Apps Script, you can edit them directly in the script editor, write them from scratch or convert existing functions into macros.


Creating Macros in Apps Script

You can take data cleaning functions written in Apps Script and use them as macro functions. The easiest way is by importing an existing function from the Google Sheets editor.

If that method does not suit your needs, you can also create macros by coding them directly or recording your actions in the sheet.


Coding Macros in Apps Script

  1. In the Google Sheets user interface, select Extensions > Apps Script to open the script bound to the sheet in the Apps Script editor.
  2. Write the macro function. Macro functions should take no arguments and return no values.
  3. Edit your script manifest to create the macro and link it to the macro function. Assign it a unique keyboard shortcut and name.
  4. Save the script project. The macro is then available for use in the sheet.
  5. Test the macro function in the sheet to verify that it functions as intended.

Recording Macros in Sheets

  1. In the spreadsheet menu, click Extensions > Macros > Record macro.
  2. At the bottom, choose which type of cell reference you want your macro to use, that is, Use absolute references and Use relative references.
  3. Complete the task you want to record. When you are done, click Save.
  4. Name the macro, create a custom shortcut and then click Save.

How to Schedule Your Macro

You can set your macro to run based on actions, calendar updates, time intervals or a chosen time and date.

  1. On your computer, open a spreadsheet at sheets.google.com.
  2. Click Tools > Script editor.
  3. At the top, click Edit and then Current project's triggers.
  4. At the bottom right, click Add trigger and select your options.
  5. Click Save.

How to Edit Your Macro

Once your macros are set up, you may need to adjust them as your data cleaning needs evolve.

You can edit macros attached to a sheet by doing the following:

  1. In the Google Sheets user interface, select Extensions > Macros > Manage macros.
  2. Find the macro you want to edit and select the three-dot menu > Edit macro. This opens the Apps Script editor to the project file containing the macro function.
  3. Edit the macro function to change the macro behaviour.
  4. Save the script project. The macro is then available for use in the sheet.
  5. Test the macro function in the sheet to verify that it functions as intended.

Importing Functions as Macros

In addition to recording and editing macros, you can also import existing functions to expand your automation toolkit.

If there is already a script bound to a sheet, you can import a function in the script as a new macro and then assign it a keyboard shortcut. You can do this by editing the manifest file and adding another element to the sheets.macros[] property.

You can also follow these steps to import a function as a macro from the Sheets user interface:

  1. In the Google Sheets user interface, select Extensions > Macros > Import.
  2. Select a data cleaning function from the list presented and then click Add function.
  3. Click the close dialogue button.
  4. Select Extensions > Macros > Manage macros.
  5. Locate the function you just imported in the list and assign a unique keyboard shortcut to the macro. You can also change the macro name in this section and that name will default to the name of the function.
  6. Click Update to save the macro configuration.

Best Practices for Using Macros


Things You Cannot Do with Macros

Macros automate repeated interface actions but have several limitations to keep in mind.


Automating a Recurring Monthly CSV Export

A common automation task is a CSV export that arrives every month in the same messy format. Customer records arrive with unstandardised names, phone numbers and addresses and the file must be deduplicated against the existing customer list before use.

Macros handle the mechanical steps such as trimming whitespace and fixing case.
The matching step needs fuzzy logic, since names and addresses rarely arrive spelled exactly as stored. Flookup custom functions match the new rows against the master list, so each monthly export is standardised and deduplicated before use.


Beyond Macros with Advanced Automation

Macros automate repetitive sequences of actions. Flookup also offers custom functions, Data Cleaning Automation for supported scheduled batch jobs and the Sheets AI Assistant for formula suggestions.

These features cover tasks that are difficult or impossible to achieve with traditional macros, such as:


Schedule Recurring Deduplication

Run the macro together with Flookup fuzzy matching, then schedule the sequence with a time trigger. Each run standardises names, removes internal duplicates and matches new rows against the master list, so monthly exports follow the same format. Setup is covered in the schedule functions documentation.

Frequently Asked Questions

Can I automate data cleaning with Google Sheets macros?

Yes, Google Apps Script macros can automate repetitive cleaning tasks such as removing duplicates, trimming whitespace and standardising text case.
However, macros have limitations with fuzzy matching and complex data quality rules, where an add-on such as Flookup or custom Apps Script code can help.

What is the easiest way to automate data cleaning?

The approach depends on technical skill level.
For non-technical users, Google Sheets add-ons such as Flookup provide cleaning functions through a familiar spreadsheet interface. For developers, Python scripts with pandas offer more control over the workflow.

Can macros handle fuzzy matching for data cleaning?

Standard Google Sheets macros cannot perform fuzzy matching out of the box. They rely on exact-match operations.
To automate fuzzy matching, you need either custom Apps Script code implementing Levenshtein or similar algorithms or an add-on such as Flookup that provides built-in fuzzy matching capabilities.

How do I automate a recurring monthly CSV export into the same clean format?

Schedule the mechanical steps with macros or triggers and run the matching step with Flookup fuzzy matching.
Each monthly export is cleaned, standardised and deduplicated against the existing list on the same schedule, so the output format stays identical every month without manual work.


You Might Also Like