In this tutorial, you will learn how to run a script in Google Sheets. Google Sheets is a powerful tool right out of the box, but it becomes even more powerful once you begin using scripts to add additional, custom features to your spreadsheets. Scripts can be used to process data, apply formatting, and much more. This tutorial outlines how to run an
already-written script, but does not go into details of developing scripts Before running a script, you have to add it to your Google Sheet Step 1Open the Extensions Menu and choose Apps Script to launch the Script Editor. If you haven’t switched to the new menu layout, you’ll find the Script Editor in the Tools menu. Step 2The Script Editor will load in a new browser tab. Delete the existing text from the editor region Step 3Type in or copy paste the script you want to run. If you don’t have a script already, you can use the following code that writes “Hello World” to the selected cell. function helloWorld() { const cell = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveRange(); cell.setValue(“Hello World”); } Step 4Add this tag to your code to make sure the script only affects the current spreadsheet /** * @OnlyCurrentDoc */ Step 5Name your script project by clicking on the heading that says Untitled Project then typing in a descriptive name. For this example, we’ll call the project “Hello World”. Step 6Click the save button to save your script. Step 7The script is now ready to run Running Your ScriptThe first time you run a script in Google Sheets under a given Google Account, you’ll have to authorize the code to run Here’s how: Step 1In the script editor, make sure the script you want to run is selected in the Select Function to Run dropdown, then click the Run button Step 2Wait for the popup to appear, then click Review Permissions Step 3Step 4Click on the account you want to run the script under Step 5Review the listed permissions, then click Allow if you are ok with granting the script these permissions and trust the source Step 6The script is now authorized. Click Run one more time to run the script and paste “Hello World” into the active cell(s) Run a Script from a ButtonYou can run scripts from the script editor at any time, but it’s easier to run them directly from the spreadsheet. One way to do this is using a button. Here’s how: Step 1Open the Insert menu and choose Drawing Step 2Use the Drawing Editor tools to create a button, then click Save and Close to add it to your spreadsheet Step 3Select the button and click on the 3 dots that appear to open the menu, then choose Assign Script Step 4Type the name of the function you want to run exactly as it appears in the Script Editor. Then click Ok. Step 5You can now run the script by clicking the button SummaryExample Spreadsheet: Make a copy of the example spreadsheet In this tutorial, I covered how to run a script in Google Sheets. Want more? Check out all the Google Sheets Tutorials. You might also like:Why my Google sheet does not have script editor?If the Tools --> Script Editor and the Add-ons menu options are missing when you open the file, it probably isn't actually a Google Sheets file. Make sure to navigate to File --> Save As Google Sheets. Then the Script Editor option in the Tools menu and the Add-ons menu will be available.
How do I enable scripts in Google Sheets?Schedule your macro. On your computer, open a spreadsheet at sheets.google.com.. Click Tools. Script editor.. At the top, click Edit. Current project's triggers.. At the bottom right, click Add trigger and select your options.. Click Save.. How do I access the script editor in Google Sheets 2022?Open the Extensions Menu and choose Apps Script to launch the Script Editor. If you haven't switched to the new menu layout, you'll find the Script Editor in the Tools menu.
Where is script editor in Google Docs?Just open Docs or Sheets and go to Extensions, then click on Apps Script. A new tab with the Apps Script editor interface will open. There, you can create new scripts or run existing ones (use the Run button on the toolbar).
|