What is Google Apps Script?
Google Apps Script (GAS) is a cloud-based scripting language that allows you to automate repetitive tasks in Google Sheets, Docs, Gmail, and other Google services. It’s based on JavaScript, making it easy for beginners to learn.
✅ Automate Data Entry
✅ Create Custom Functions
✅ Send Automated Emails
✅ Generate Reports & Dashboards
By the end of this guide, you’ll have written your first script and be ready to automate Google Sheets like a pro! 🚀
Step 1: Open the Google Apps Script Editor
1️⃣ Open a Google Sheet
2️⃣ Click on Extensions > Apps Script
3️⃣ A new Apps Script editor will open
🎉 Now you’re ready to write your first script! 🎉
Step 2: Write Your First Google Apps Script
Let’s start with a simple script to insert a timestamp when a button is clicked.
Example: Add Timestamp in Column B
function addTimestamp() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var row = sheet.getLastRow() + 1;
sheet.getRange(row, 2).setValue(new Date()); // Inserts timestamp in Column B
}
🔹 What this script does:
✅ Gets the active sheet
✅ Finds the next available row
✅ Inserts the current date & time in Column B
📌 How to Run the Script:
1️⃣ Click the Run ▶️ button in the Apps Script editor
2️⃣ Grant permissions when prompted
3️⃣ Check Column B in your Google Sheet – you’ll see a timestamp! 🎉
Step 3: Automate the Script with a Button
Want to run the script with a click of a button?
How to Add a Button in Google Sheets:
1️⃣ In your Google Sheet, click Insert > Drawing
2️⃣ Create a button shape and click “Save”
3️⃣ Click on the button, select Assign Script, and type:
addTimestamp
4️⃣ Now, clicking the button adds a timestamp automatically!
🎯 Tip: You can also assign scripts to menus, triggers, or keyboard shortcuts.
Step 4: Automate Google Sheets with Triggers
Want your script to run automatically at a specific time?
How to Set Up an Apps Script Trigger:
1️⃣ Go to Apps Script > Triggers (Clock Icon) > Add Trigger
2️⃣ Choose your function (addTimestamp
)
3️⃣ Select Time-driven and set the schedule (e.g., every hour)
4️⃣ Click Save
✅ Now, the script runs automatically without manual execution!
Step 5: Sending Automated Emails from Google Sheets
Want to send an email when new data is added? Try this script:
Example: Send Email Notification
function sendEmailNotification() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = sheet.getLastRow();
var email = "your-email@example.com"; // Replace with your email
var message = "New entry added: " + sheet.getRange(lastRow, 1).getValue();
MailApp.sendEmail(email, "New Google Sheets Entry", message);
}
📌 How it Works:
✅ Reads the latest row from Column A
✅ Sends an email notification with the new entry
🎯 Tip: Use MailApp.sendEmail()
to automate report emails, reminders, or alerts!
Step 6: Create a Custom Function in Google Sheets
Did you know you can create your own custom functions?
Example: Custom Function to Convert Currency
function convertToEuros(amount) {
var exchangeRate = 0.85; // Example USD to EUR rate
return amount * exchangeRate;
}
📌 How to Use in Google Sheets:
Simply type:
=convertToEuros(100)
✅ This will return €85! 💰
Step 7: Explore More Automation Possibilities
🔹 Auto-generate reports 📊
🔹 Merge Google Sheets data
🔹 Sync Google Sheets with Gmail or Drive
🔹 Integrate APIs (e.g., Weather, Stocks, Crypto)
📌 Pro Tip: Use Logger.log()
for debugging and SpreadsheetApp.getUi().alert()
to display messages.
Conclusion: Start Automating Today!
You just learned how to:
✅ Write your first Google Apps Script
✅ Add a button to run scripts instantly
✅ Use triggers for automation
✅ Send automated emails
✅ Create custom functions
🚀 Next Steps:
🔹 Want to automate data entry? Learn about onEdit()
triggers!
🔹 Need to schedule reports? Try Time-driven triggers
!