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
Run setValue, setValues, or format changes as usual in your function.
-
2
Call SpreadsheetApp.flush() before reading back the same cells or relying on dependent formulas.
-
3
Flush applies pending updates to the spreadsheet service, not to other users' open sessions instantly.
-
4
Combine with Utilities.sleep only when you truly wait on external recalc, and keep sleeps short.
-
5
Log before and after reads while debugging timing issues in Executions.
-
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.
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
The First Thing I Do When Starting a Google Sheet
Self Destructing Google Sheet
Convert Google Sheets into a REST API
Create an Internal Google Sheets Add-on
Get Every Editor on Every Google File I Own
Related blog posts
Guides that explain SpreadsheetApp.flush in more depth.
What's Better Than Google Sheets?
Nothing is better than Google Sheets. You just need to learn more about the unlimited power of Google Sheets. Functions, Formulas, Apps Script and more.
Read post →How to reference a different Google Spreadsheet in Apps Script?
Transferring Data Between Cells in Different Spreadsheets
Read post →How to Use Google Sheets as a Website Database
Did you know you can use Google Apps Script to turn a Google Sheet into a free, auto-syncing database for your website? This guide shows you exactly how to set it up. You’ll prepare your spreadsheet, write a few lines of code and publish your site. Don’t worry if you’re not a developer, we’ll walk you through it. Why Use Google Sheets as a Database? For small projects, Google Sheets offers many advantages over traditional databases: * Free hosting and storage * Easy to edit data without...
Read post →Related terms
Apps Script triggers
Triggers tell Apps Script when to run a function: on edit, on open, on a schedule, or when a form is submitted. Simple triggers use reserved names like onEdit. Installable triggers are created in the Apps Script Triggers page and can do more, including running as a specific user or on a timer.
Read guide →Google Sheets automation
Automation means work happens without repeating the same clicks every day: imports update, emails send, rows move, and dashboards refresh. In Sheets, automation usually stacks built-in features, Apps Script, and sometimes the Sheets API or add-ons. Start with the lightest tool that still solves the job.
Read guide →Script Editor
The Script Editor is the Apps Script workspace inside your spreadsheet where you write JavaScript that talks to Sheets, Gmail, and other Google services. You open it from Extensions > Apps Script. Every function you save can be run manually, bound to a trigger, or linked from a custom menu.
Read guide →Google Sheets workflows
A workflow is the path work takes through your sheet: intake, review, approval, done. Good workflows use consistent columns, statuses everyone understands, and just enough automation to move tasks forward without hiding steps from the team.
Read guide →Done reading about SpreadsheetApp.flush?
Membership unlocks 600+ 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.