Flag overdue rows
Loop column B dates against today in a script function. Write "Overdue" to column E only when the date is past and status in column D is not "Paid".
Loops in Apps Script let you repeat code over rows, columns, sheets, or API pages. You read ranges into arrays with getValues(), process each item in a for or forEach loop, then write results back in one setValues() call when possible. Batch reads and writes beat cell-by-cell updates for speed and quota limits.
Use loops when you need to scan many rows, clean data, build summaries, or call an API for each record. Pair loops with arrays from getValues() for reports, deduplication, and row-by-row rules that formulas cannot express cleanly.
Skip loops when a single QUERY, MAP, or ARRAYFORMULA can do the job in the sheet without script. Avoid looping every cell on large tabs without batching; execution time and UrlFetch quotas add up fast.
Open Extensions > Apps Script and define a function that gets the target range with getRange().
Call getValues() once to load data into a two-dimensional JavaScript array.
Use for (let i = 0; i < rows.length; i++) or rows.forEach() to read each row and build an output array.
{:"Apply your logic inside the loop"=>"trim text, compute totals, skip blanks, or collect matches."}
Write the output array back with setValues() in one range update instead of many setValue() calls.
Test on a small sample range first, then add Logger.log counts and guard rails for empty data.
Loop column B dates against today in a script function. Write "Overdue" to column E only when the date is past and status in column D is not "Paid".
Read column A into an array, track seen emails in a Set, and write "Duplicate" in column B for second and later occurrences.
Use a while loop with a page token from UrlFetchApp until no next page remains, pushing each record into a master array before flushing to the sheet.
Build this without starting from a blank cell
Use a Better Sheets tool for Apps Script loops, then watch a walkthrough when you want the full pattern.
Watch how Apps Script loops works
Guides that explain Apps Script loops in more depth.
Did you know you can actually code in Google Sheets?
Read post →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 →If you know how to code, you'll learn in this step-by-step tutorial how to code in Google Sheets.
Read post →The onEdit trigger runs a script automatically when someone changes a cell in your spreadsheet. It is one of the simplest ways to make Sheets react to user input without clicking a custom menu. You define the function in Apps Script and bind it to the onEdit event for that file.
Read guide →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 →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 →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 →Done reading about Apps Script loops?
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.