
📎 This article includes 2 downloadable practice files ↓
In this article
Apps Script is to Google Workspace what VBA is to Excel: code that automates Sheets, Docs, Gmail, Calendar and Drive. It’s JavaScript, it runs in Google’s cloud, and you can start with a 15-line script.
Open the editor
In the practice sheet: Extensions › Apps Script. Delete the empty function and paste the script from the download.
The script, explained
function dailySummary() {
const sh = SpreadsheetApp.getActive().getSheetByName('Orders');
const rows = sh.getDataRange().getValues().slice(1); // all rows except the header
const byRegion = {};
rows.forEach(r => { byRegion[r[2]] = (byRegion[r[2]] || 0) + Number(r[6]); });
const lines = Object.keys(byRegion).sort()
.map(k => k + ': Rs ' + byRegion[k].toLocaleString('en-IN'));
MailApp.sendEmail(Session.getActiveUser().getEmail(), 'Daily sales summary', lines.join('\n'));
}
getValues()reads the sheet into a 2-D array;r[2]is column C (counting from 0),r[6]is column G.- The loop totals amounts per region.
MailApp.sendEmailsends the summary to you.
Run it and grant permission
Save (Ctrl+S), choose dailySummary in the toolbar, click Run. Google asks for permission to see your spreadsheets and send email as you. Read the list; for your own script it’s expected. Check your inbox.
A menu for one-click use
function onOpen() {
SpreadsheetApp.getUi().createMenu('Reports')
.addItem('Email me the summary', 'dailySummary').addToUi();
}
Reload the sheet: a Reports menu appears for anyone who uses the file.
Run it every morning: triggers
In the editor, the clock icon (Triggers) › Add Trigger › function dailySummary › Time-driven › Day timer › 8–9 am. Now it runs daily even when your computer is off.
Where to go next
- Create a Google Doc from a template for each new form response.
- Save Gmail attachments to a Drive folder.
- Add calendar events from a sheet of dates.
If you know VBA, the ideas carry over directly; see the Excel VBA course for the Excel side.
Where beginners go wrong
| Problem | Cause |
|---|---|
| “Cannot read properties of null” | Sheet name doesn’t match exactly (‘Orders’) |
| Wrong column | Arrays count from 0: column A is r[0] |
| Script slow on big sheets | Reading cell by cell; read the whole range once with getValues() |
| Email quota errors | Free accounts have daily sending limits |
That’s the Google Workspace course.
Practice
Download the practice file below and upload it to Google Drive (File › Import in Sheets). Paste the script from the second download into Extensions › Apps Script and run it.
📎 Practice files for this article
- 📗Practice sheet (import into Google Sheets)60 orders plus a Tasks sheet: QUERY, FILTER, UNIQUE, SPLIT, ARRAYFORMULA, GOOGLETRANSLATE, SPARKLINE and more.⬇ XLSX · 8 KB
- 📄Apps Script: daily summaryA commented script that emails you sales by region and adds a custom menu.⬇ TXT · 1 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.