Apps Script for Google Sheets is the productivity solution you've been missing out on
Google Sheets can do a lot of things - but with Apps Script, it can do it all. Many people have used Sheets for years without ever touching it. Once you learn it, you'll start to learn how to automate tasks that you didn't even realize were slowing you down.
Automate boring tasks
If you're tired of doing the same tasks over and over again in Google Sheets, whether it's inserting dates, cleaning up text, applying formatting, or exporting data, Apps Script can help you automate it.
For example, you can easily insert the current date into Google Sheets by pressing Ctrl + ; on Windows or Cmd + ; on Mac. But if you need the current date in a specific format like yyyy-MM-dd, you have to use a formula or do some manual formatting. With Apps Script, you can create a function that takes the current date, formats it however you want, and then inserts it into selected cells.
You only need to do this once and can reuse it wherever you need it. Here's an example of what the script looks like:
function insertCurrentDate() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var selectedCell = sheet.getActiveCell(); var currentDate = new Date(); var formattedDate = Utilities.formatDate(currentDate, Session.getScriptTimeZone(),'yyyy-MM-dd'); selectedCell.setValue(formattedDate); }
The article will guide you how to run the above code from inside the spreadsheet in the next section.
Create custom spreadsheet
One way Apps Script helps you customize your spreadsheet is by allowing you to create specialized tools that streamline your workflow. For example, you can insert a button that applies formatting or performs advanced calculations, or create a dashboard that makes it easy to analyze your data. These capabilities go beyond anything Google Sheets can do on its own.
Continuing with the example from the previous section, we can add a custom menu item that allows us to run a function from within the spreadsheet. Here is the script that does this (inserted above the function from the previous section):
function onOpen(){ var ui = SpreadsheetApp.getUi(); ui.createMenu('My Menu').addItem('Insert Current Date', 'insertCurrentDate').addToUi(); }
After running this code in Apps Script and refreshing Google Sheets, you should see My Menu appear in the top menu. You can now insert the current date into the selected cell by clicking My Menu > Insert Current Date .
Perform specific calculations through custom functions
Google Sheets doesn't always have the functions you need to perform specific calculations. In cases like this, it's best to create your own function using Apps Script, insert the calculation into it, and use it in your spreadsheet (just like any other function). This also means you don't have to repeat complex calculations throughout your script, keeping your spreadsheet cleaner and easier to read.
Consider the function below, which accepts a date and checks the number of days elapsed since the current date (similar to calculating the difference between two dates) to determine the due date:
function CHECKDUEDATE(inputDate) { var today = new Date(); var timeDiff = today - inputDate; var daysDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); if (daysDiff < 0){ return "Overdue!" } else if (daysDiff > 0) { return "Due in " + daysDiff.toString() + " days!" } else { return "Due today!" } }
Depending on the date entered, it will indicate whether it is overdue, if the date difference is less than 0, how many days are left if greater than 0, or the due date if zero.
The biggest advantage of Apps Script is that you can create a time-based trigger to run a function at a specific time (e.g. midnight) to dynamically update the due date. It can even be used for conditional formatting - there are so many possibilities.
You can use Apps Script with other Google services
Apps Script lets you integrate spreadsheets with other Google services, including Gmail , Google Drive , and Google Docs . This capability lets you build comprehensive workflows that span multiple tools in the Google ecosystem.
Here is an example of a script that extracts the body text from a Google Docs document and inserts it into cell A1 :
function getBodyTextFromGoogleDoc() { const doc = DocumentApp.openById("insert Google Docs ID here"); const bodyText = doc.getBody().getText(); const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const targetRange = sheet.getRange("A1"); targetRange.setValue(bodyText); }
Remember to replace "insert Google Docs ID here" in the second line with the ID of the Google Docs document you want to get the main content from (don't remove the parentheses).
You should read it
- Use Google applications more efficiently with Google Apps Script
- Tricks using Google Sheets should not be ignored
- How to create graphs, charts in Google Sheets
- How to align spreadsheets before printing on Google Sheets
- AI Tools for Google Sheets
- How to enter 0 in Google Sheets
- Instructions for importing JSON into Google Sheets
- How to create a phone number can be called on Google Sheets
May be interested
- How to enter 0 in Google Sheetsnormally when entering 0 on google sheets, it will automatically disappear if that 0 is in front of the number line. so how to re-display 0 in google sheets.
- How to create a phone number can be called on Google Sheetsgoogle sheets has a call feature when entering phone numbers into data tables, via callers installed on the computer.
- How to view editing history on Google Sheetsgoogle sheets will automatically save the content edits on the file so that users can review it when needed, or restore the modified version.
- 6 useful functions in Google Sheets you may not know yetin this article, i will show you 6 useful functions for the google sheets spreadsheet that you should know such as vlookup, countif, sumif, join, index, ... in addition, you can refer to the functions. and other tips follow the link in the post.
- How to fix Google Sheets not allowing scrollinggoogle sheets is a free and easy to use spreadsheet application that works right out of the box. however, sometimes users face some glitches.
- How to count words on Google Sheetson google sheets, to count the number of words in each cell, users can use the formula with the counta function.
- How to set up the right to edit spreadsheets on Google Sheetswhen working on google sheets online, if you want to restrict editing of certain column or row data areas, you can set editing rights on google sheets.
- How to write notes, comments on Google Sheetson google sheets has a comment writing feature, notes in the data box can help users understand the content while working online with many people.
- How to insert checkboxes on Google Sheetsadding checkboxes to optional list data on google sheets makes it easier for users to manage content.
- How to convert Google Sheets to PDFgoogle sheets is indeed a useful online tool, but it's not always the best spreadsheet presentation. for this, a pdf file may be a better choice.