What does SpreadsheetApp.flush do in Google Sheets?

SpreadsheetApp.flush() forces pending spreadsheet changes from your script to apply immediately. Apps Script batches some writes for performance, so flush makes sure the grid, charts, or a following read sees updates right away. It is a small call that matters in timing-sensitive automations.

When to use it

Use flush after writes when the next line depends on updated values: re-read a cell you just set, refresh a chart, coordinate with another trigger, or pause until the sheet reflects changes before UrlFetchApp fires.

When to skip it

Skip flush on every setValue in a loop. Unneeded flush calls slow scripts and rarely fix logic bugs that come from wrong range references instead.

How it works

  1. 1

    Run setValue, setValues, or format changes as usual in your function.

  2. 2

    Call SpreadsheetApp.flush() before reading back the same cells or relying on dependent formulas.

  3. 3

    Flush applies pending updates to the spreadsheet service, not to other users' open sessions instantly.

  4. 4

    Combine with Utilities.sleep only when you truly wait on external recalc, and keep sleeps short.

  5. 5

    Log before and after reads while debugging timing issues in Executions.

  6. 6

    Remove extra flush calls once the script works to keep runs fast.

Examples in Google Sheets

Write then validate

Set a status cell to Processing, flush, then read it back to confirm before calling an external API.

Trigger coordination

After copying rows to a Log tab, flush so a second function started manually sees the new last row count.

Format then export

Apply number formats to a range, flush, then export the sheet range to PDF so the file matches the display.

Build this without starting from a blank cell

Use a Better Sheets tool for SpreadsheetApp.flush, then watch a walkthrough when you want the full pattern.

Better Sheets resources

Common mistakes

  • Calling flush thousands of times inside tight loops, killing performance.
  • Expecting flush to force formula recalculation across the entire workbook instantly in all cases.
  • Using flush instead of fixing wrong getLastRow logic after appendRow.
  • Assuming flush makes changes visible to another user's open tab in real time.
  • Adding long Utilities.sleep after every flush without measuring if it is needed.

Frequently asked questions

When is flush required?
When the same script must read or depend on values it just wrote before the function ends. Many simple scripts never need it.
Does flush commit to version history?
Changes are saved like normal edits. flush does not create a separate version snapshot.
Can flush fix onEdit loops?
No. Loops from writing back to the trigger cell need logic checks on oldValue, not flush.
Does flush work with getActiveSpreadsheet?
Yes. Call SpreadsheetApp.flush() on the global service after changes to the active or opened spreadsheet.
Is flush needed after appendRow?
Usually getLastRow works in the same run without flush. Use flush if the next step reads from another process or timing fails.
Does flush affect multiple sheets?
It flushes pending changes for the spreadsheet object you have been modifying in that script run.
Can I flush from a trigger?
Yes. Installable and simple triggers can call SpreadsheetApp.flush like any other function.
What is the alternative to flush and sleep?
Restructure code to pass values in variables instead of re-reading the grid, which is faster and more reliable.

Related Tutorials

Watch how SpreadsheetApp.flush works

Browse more tutorials
The First Thing I Do When Starting a Google Sheet

The First Thing I Do When Starting a Google Sheet

Are you tired of the default look of your Google Sheets? In this video, ...
Self Destructing Google Sheet

Self Destructing Google Sheet

Create a sheet that can trash itself. It can delete itself instantly or ...
Convert Google Sheets into a REST API

Convert Google Sheets into a REST API

How to use Google Sheets as a database by turning it into a REST API wit...
Create an Internal Google Sheets Add-on

Create an Internal Google Sheets Add-on

The entire process to create and publish a Google Sheets Add-on internal...
Get Every Editor on Every Google File I Own

Get Every Editor on Every Google File I Own

Get every editor if you're looking for the sheets and documents you've s...
Two Things to Know When Starting to Learn Google Sheets

Two Things to Know When Starting to Learn Google Sheets

Two things I would teach every beginner to immediately improve your skil...

Related blog posts

Guides that explain SpreadsheetApp.flush in more depth.

Browse the blog

Related glossary terms

Done reading about SpreadsheetApp.flush?

Membership unlocks 636+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.

Need this once

Jump to a free tool or a single tutorial for this topic.

Learning Sheets for real

Unlock the full library, generators, and templates with membership.