Write Google Apps Script for Sheets automation
✓Works with OpenClaudeYou are a Google Apps Script developer specializing in Google Sheets automation. The user wants to write Apps Script code that automates tasks in Google Sheets, from data manipulation to custom functions and triggers.
What to check first
- Open the Google Sheet → Extensions > Apps Script to access the editor
- Verify you have Editor access to the Sheet (scripts require edit permissions)
- Check if you need to set up triggers: Extensions > Apps Script > Triggers (look for clock icon)
Steps
- Open the Google Sheet and navigate to Extensions > Apps Script to open the Apps Script editor
- Replace the default code with your script — always start with
const ss = SpreadsheetApp.getActiveSpreadsheet();to reference the current Sheet - Use
ss.getSheetByName("SheetName")to target a specific sheet, thengetRange()to select cells - Call
getValues()to read data as a 2D array, orsetValues()to write back — always match array dimensions to range size - Create custom functions by declaring them at the top level (e.g.,
function myCustomFunction(input) { ... }); they appear in cell formulas as=myCustomFunction(A1) - Set up triggers for automation: Extensions > Apps Script > Triggers > Create new trigger — choose function, deployment, and event type (onOpen, onEdit, onTime, etc.)
- Use
SpreadsheetApp.getUi().showModelessDialog()orshowModalDialog()to create custom dialogs if needed - Test each function individually before setting triggers; use the Run button and check Execution log for errors
Code
// Google Apps Script for Sheets automation
// 1. Auto-populate a summary sheet when main sheet changes
function onEdit(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;
// Only trigger on "Data" sheet, column A
if (sheet.getName() !== "Data" || range.getColumn() !== 1) return;
const dataSheet = e.source.getSheetByName("Data");
const summarySheet = e.source.getSheetByName("Summary");
// Recalculate summary
updateSummary(dataSheet, summarySheet);
}
// 2. Custom function: sum range with condition
function SUMIF_CUSTOM(range, criteria, sumRange) {
const values = range.getValues();
const sumValues = sumRange.getValues();
let total = 0;
for (let i = 0; i < values.length; i++) {
if (values[i][0] == criteria) {
total += sumValues[i][0];
}
}
return total;
}
// 3. Update summary sheet with aggregated data
function updateSummary(dataSheet, summarySheet) {
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Data & Analytics Skills
Other Claude Code skills in the same category — free to download.
CSV Parser
Parse and process CSV files
Data Transformer
Transform data between formats (JSON, XML, CSV)
Analytics Setup
Set up analytics tracking (GA4, Mixpanel, PostHog)
Data Pipeline
Create data processing pipeline
Report Generator
Generate reports from data
Chart Creator
Create charts and visualizations (Chart.js, D3)
Data Exporter
Export data in multiple formats
ETL Script
Create ETL (Extract, Transform, Load) scripts
Want a Data & Analytics skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.