Can you run code in Google Sheets?

Download Article

Download Article

This wikiHow teaches you how to access Google's script editor in a desktop internet browser, and run code in the editor for testing purposes.

  1. Can you run code in Google Sheets?

    1

    Open Google Sheets in your internet browser. Type sheets.google.com in your browser's address bar, and hit Enter or Return on your keyboard.

  2. Can you run code in Google Sheets?

    2

    Click a spreadsheet file. Find the spreadsheet you want to run a script on, and open it.

    Advertisement

  3. Can you run code in Google Sheets?

    3

    Click the Tools tab. This button is on a tabs bar below the file name in the upper-left corner of your spreadsheet. It will open a drop-down menu.

  4. Can you run code in Google Sheets?

    4

    Tap Script editor on the Tools menu. This will open the Google's browser-based script editor in a new tab.

  5. Can you run code in Google Sheets?

    5

    Create your script in the script editor. You can type your script here, or delete everything on the page and paste code from your clipboard.

    • If you're looking for some useful scripts, Google offers a few basic suggestions in their developer guides.

  6. Can you run code in Google Sheets?

    6

    Name your script project. Click the "Untitled project" heading in the upper-left corner of your window, and enter a title for your new script project in the "Edit Project Name" window.

  7. Can you run code in Google Sheets?

    7

    Click the

    Can you run code in Google Sheets?

    icon to run your script. This button is on a toolbar below the file name and tabs bar in the upper-left corner of your window. It will save and run the code in the script editor.

    • If you're prompted to authorize script testing, click the Review Permissions button, and Allow script testing in your account settings.

  8. Advertisement

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

Thanks for submitting a tip for review!

About This Article

Article SummaryX

1. Open Google Sheets.
2. Click a file.
3. Click the Tools tab.
4. Click Script editor.
5. Enter your script into the editor.
6. Click the Play/Run icon on the toolbar at the top.

Did this summary help you?

Thanks to all authors for creating a page that has been read 65,611 times.

Is this article up to date?

There is a way to use Google Docs as a programming IDE and run JavaScript code inside the editor.

Can you run code in Google Sheets?

You have been using Google Docs to write documents and essays but did you know that the same editor can also be used to write and run JavaScript code?

It is no replacement for a dedicated IDE like Visual Studio code but Google Docs can be used as a JavaScript playground to quickly run code snippets.

Here’s a sample document written in Google Docs and the document body contains a JavaScript function that calculates the number of days left until the next Christmas.

Go to the Code Runner menu, choose Run JavaScript and the output of the function will display in a popup. See demo

Can you run code in Google Sheets?

Code Runner in Google Docs

Internally, there’s a little Google Apps Script that is doing the magic. It reads the body of your Google Document as a text string and uses the eval() function of JavaScript to evaluate the text.

/**
 * @OnlyCurrentDoc
 */

function codeRunner() {
  const doc = DocumentApp.getActiveDocument();
  const text = doc.getBody().getText();
  const response = eval(text);
  DocumentApp.getUi().alert(response);
}

function onOpen() {
  const ui = DocumentApp.getUi();
  const menu = ui.createMenu('Code Runner');
  menu.addItem('🦄 Run JavaScript ', 'codeRunner');
  menu.addToUi();
}

Related reading:

  • Call JavaScript functions by Name
  • JavaScript design patterns

Can you code in Google Sheets?

While Google Sheets provides a lot of functionality for everyone, you can also code something that's more suited to your needs. And since you can reuse the code, again and again, it makes you a lot more productive and efficient.

Can you run Python code in Google Sheets?

Conclusion. The new Google Sheets support in xlwings allows you to build tools in Python that you could previously only build in Google Apps Script, i.e., JavaScript.

Can you run JavaScript in Google Sheets?

Step 3 — Use the function to run JavaScript code in Google Sheets. You can now use the =RUNJS() function in your spreadsheet. To try it out, enter 1+1 in cell A2 and enter the formula =RUNJS(A2) in cell B2. The resulting value in cell B2 is 2, which is the output of evaluating the JavaScript expression 1 + 1 .

Can you run scripts on Google Sheets app?

Learn more. Unfortunately, Scripts do not run on mobile devices. The mobile version is not a full-blown version like the one on PCs.