Apps Script 'Exceeded Maximum Execution Time' and Daily Quota Errors
Short answer: Apps Script stops any single run after a fixed time limit (six minutes for a normal script), and it also caps daily usage such as emails sent, with lower caps on free Gmail accounts than on Google Workspace. "Exceeded maximum execution time" means one run took too long; "Service invoked too many times for one day" means a daily quota ran out. Fix the first by reading and writing the sheet in batches, processing rows in chunks, saving a progress marker and letting a time trigger continue the job. Fix the second by checking the remaining quota before sending and spreading work across days, or moving heavy jobs to a proper backend.
Read the error message carefully
The two messages point to different problems:
| Message | Meaning | Typical cause |
|---|---|---|
| Exceeded maximum execution time | One run hit the time limit | Looping over thousands of rows with a read or write per row |
| Service invoked too many times for one day: email | Daily email recipient quota used up | Sending a reminder to every row in one go |
| Service invoked too many times for one day: urlfetch | Daily fetch quota used up | Calling an API for every row |
| Too many simultaneous invocations | Too many runs at once | Several triggers or users running the same script |
Google publishes the current figures on its Apps Script quotas page. Limits vary by account type and can change, so check there rather than relying on numbers copied into old forum posts.
Why scripts run slowly in the first place
Every call to getValue(), setValue(), getRange() or a Gmail or Calendar method is a round trip to a Google service. A script that processes 3,000 invoice rows like this:
for (let i = 2; i <= 3000; i++) {
const amount = sheet.getRange(i, 4).getValue();
sheet.getRange(i, 6).setValue(amount * 1.2);
}
makes 6,000 service calls. That alone can push it past the limit. Google's best practices guide recommends minimising these calls above all else.
Fix 1: Batch reads and writes
Read the whole block once, work on it in memory, and write it back once:
const data = sheet.getRange(2, 1, sheet.getLastRow() - 1, 6).getValues();
for (const row of data) {
row[5] = row[3] * 1.2;
}
sheet.getRange(2, 1, data.length, 6).setValues(data);
Two service calls instead of thousands. For most office scripts, this change alone removes the time error. Also avoid SpreadsheetApp.flush() and formatting calls inside loops, and move any getSheetByName lookups outside the loop.
Fix 2: Process in chunks with a progress marker
Some jobs are genuinely long, such as creating a PDF per customer or calling an external API. Split them:
- Store the last processed row in Script Properties.
- Each run starts from that row and stops before the time limit, for example after four and a half minutes.
- Save the new position before stopping.
- Schedule the next run.
A simplified pattern:
function processBatch() {
const props = PropertiesService.getScriptProperties();
let start = Number(props.getProperty('nextRow') || 2);
const began = Date.now();
const last = sheet.getLastRow();
while (start <= last && Date.now() - began < 270000) {
handleRow(start);
start++;
}
props.setProperty('nextRow', String(start));
}
Keep handleRow itself efficient, and mark each processed row in a status column so you can see progress and avoid repeats if a run fails halfway.
Fix 3: Let a time trigger continue the job
Add a time-driven trigger, either through the Triggers page in the editor or in code, that runs processBatch every few minutes. When the progress marker passes the last row, the function can reset the marker and delete its own trigger, or simply do nothing until new rows appear.
Be aware that triggers also count toward a daily total runtime, which again differs by account type. A job that runs every minute all day may hit that ceiling, so pick a sensible interval.
Fix 4: Check the email quota before sending
Emails count by recipient, not by message. Before a mail loop, check what is left:
const remaining = MailApp.getRemainingDailyQuota();
Then send only that many, mark those rows as sent, and let tomorrow's trigger continue with the rest. Other practical steps:
- Send one summary email to a team instead of one per row.
- Use a group address as the recipient rather than listing every member.
- Move marketing or high-volume mail to an email service built for it, not Apps Script.
- Confirm the account type: a script running under a free Gmail account has a much smaller allowance than one under a Workspace account.
Fix 5: Avoid running the same script many times at once
If several people press the same custom menu button, or onEdit triggers fire constantly, you can hit concurrency limits. Use LockService to make later runs wait or exit, and prefer a scheduled batch over an edit trigger for heavy work.
When to move the job elsewhere
Apps Script is excellent for light office automation. Consider another home when:
- The data grows into tens of thousands of rows and keeps growing.
- The job must finish within a set time, every time, for customers.
- You send hundreds of emails daily.
- You call external APIs with their own rate limits and retries.
Options include an automation platform with queues and retries, a small cloud function on a schedule, or a proper database with a lightweight app in front of it. The sheet can stay as the human-friendly view while the heavy lifting moves out.
FAQ
Can we increase the six-minute limit?
Not for a normal script run. Restructure the work into batches and chunks instead.
Why does the script work for a colleague but not for us?
Quotas depend on the account that runs the script. A Workspace account usually has higher limits than a personal Gmail account.
When does the daily email quota reset?
Google's quotas page describes daily quotas as refreshing at the end of a 24-hour window, not at local midnight. Check the remaining amount in code rather than assuming a reset time.
Do custom functions in cells have the same limit?
No, they have a much shorter limit. Heavy work does not belong in a cell formula.
When a spreadsheet automation outgrows its limits, we can rebuild it to run reliably: drop us a line describing what it does today.