You can display a popup alert in Google Sheets to show users a message, confirmation, or error status by using the built-in Apps Script editor. You will need a Google account with access to a spreadsheet, and the spreadsheet must be open in your browser to run the script. This method works on any modern web browser, including Chrome, Firefox, Safari, and Edge, without requiring any third-party add-ons or extensions.

What You'll Need

  • A Google account (Gmail or Google Workspace).
  • A Google Sheet open in a web browser.
  • A basic understanding of where to find the script editor within the spreadsheet interface.

Step-by-Step

  1. Open the Script Editor: In your Google Sheet, click on the Extensions menu located at the top of the screen. In the dropdown menu that appears, select Apps Script. This will open a new tab or a sidebar containing the code editor.
  2. Clear Existing Code: Look at the large text area labeled "Code.gs" (or "Code.js"). If there is any code already written inside this area, click inside the box and press Ctrl+A (Cmd+A on Mac) to select all of it, then press the Delete or Backspace key to remove it completely.
  3. Insert the Message Box Function: On the first line, type the following function definition exactly as shown. This tells the script that you are creating a function named showMessageBox that takes no arguments and returns nothing.
    function showMessageBox() {
      return; // Placeholder
    }
    
  4. Add the Code Command: Move your cursor to the line immediately below the opening curly bracket { and press Enter to create a new line. Type the following command to generate the popup window:
    SpreadsheetApp.getUi().alert('Your message goes here');
    
    Replace the text 'Your message goes here' with the specific text you want to display to the user. You can use single quotes around the text, as shown above.
  5. Save the Script: Click the Save icon, which looks like a floppy disk or a file save icon, located in the toolbar at the top left of the editor. You can also press Ctrl+S (Cmd+S on Mac). Google will prompt you to name your project; you can leave this as the default name (e.g., "Project1") or enter a descriptive name like "Message Box Script". Click OK to save.
  6. Run the Script: With the script saved, look for the Run button in the toolbar. Click it. Google will ask for permission to run the script because it is a new script connected to your account. Click Review Permissions.
  7. Authorize the Script: A new window will open asking you to grant access. Select your Google account if prompted. Click Advanced, then click Go to [Project Name] (unsafe) at the bottom of the screen. Finally, click Allow. This step is necessary for the script to access your spreadsheet and display the UI elements.
  8. Verify the Message Box: The script will now run, and a standard browser popup message box will appear on your screen with the text you typed in Step 4. Click OK to dismiss the box.
  9. Connect to a Button (Optional): To make this useful for users, you can attach the script to a button. Click inside your spreadsheet to select a cell. Go to the Insert menu and select Drawing. Draw a rectangle or shape, add some text like "Submit", and click Save and Close. Click the new shape once to select it, then click the three vertical dots in the toolbar that appears above the shape. Select Assign script. In the box that appears, type the exact function name you used earlier: showMessageBox. Click OK. Now, clicking the button on your sheet will trigger the message box.

Common Mistakes

One of the most frequent errors users encounter is referencing the wrong UI object. The code Browser.msgBox() is often used in other spreadsheet programs like Excel VBA, but Google Sheets does not use this built-in object. It must be SpreadsheetApp.getUi().alert(). Using the wrong command will result in a "ReferenceError: Browser is not defined" error.

Another common issue arises when the script is not saved before running. If you type the code, click the Run button, and nothing happens, check the editor. If the code disappears, it means you forgot to save, and the changes were not applied. Always save the project before attempting to execute the function.

Permissions are also a frequent stumbling block. If you have recently changed your Google account password or if the script has not been run in a long time, you may need to re-authorize it. If you see a red error popup instead of your message, it indicates a permission issue. You can fix this by going to Extensions > Apps Script > Project Settings and toggling Run as to Me (if it is currently set to Owner), or by removing the script from your Google Drive and re-creating it to reset the permission flow.

Tips

For a more professional look, you can customize the style of the message box. The alert method typically displays a standard information icon. If you need to warn the user about an error, you might want to use a different script command. You can use SpreadsheetApp.getUi().alert('Error message', SpreadsheetApp.Ui.ButtonSet.OK_CANCEL) to create a box with an OK and a Cancel button. This allows the script to check which button was clicked using the response variable, enabling conditional logic.

When writing the text inside the quotes, remember that Google Sheets uses standard text encoding. You can include line breaks by typing \n within the string. For example, 'First line\nSecond line' will display two separate lines of text in the box.

It is important to note that scripts run in the background. If you have a very long script that takes several seconds to process data, the message box will not appear until the processing is finished. If you want to show a message immediately while the script is running, you should use the SpreadsheetApp.getUi().setAlignment('center') command to update the spreadsheet UI before the heavy processing begins.

Troubleshooting

If the message box does not appear when you click the button, the most likely cause is a typo in the script name assigned to the button. Go back to the drawing, right-click the shape, select Assign script, and double-check that the name matches exactly, including capitalization and spelling. The names are case-sensitive.

If you receive an error saying the script is taking too long, the script is likely stuck in an infinite loop or performing a calculation that is too heavy for the browser to handle. Check your code for loops that do not have a stopping condition or for complex array manipulations that might be freezing the interface. You can also try running the script directly from the editor (Step 7 in the main guide) to see the error message in the console, which will provide more specific details about where the code failed.

If the popup appears but the text is garbled or empty, ensure that you are using double quotes " for strings if you are using single quotes inside the text. For example, alert('He said "Hello"') will break the script syntax because the quotes conflict. Use double quotes for the outer string and single quotes for the inner text, or escape the inner quotes with a backslash \.

Lastly, if you are working in a shared spreadsheet and other users cannot see the message box, ensure that they have permission to run scripts. Shared scripts must be shared with them, or they must be added to the Google Sheet's editors list. If they are only viewers, they cannot execute the script and will see an error instead of the message box.

Frequently Asked Questions

Can I change the color of the message box?

No, the standard alert() function in Google Sheets does not support changing the background color or icon style. It will always appear with the default information icon and blue border. To create a custom UI, you would need to use the HTML Service, which allows for full CSS styling, but that requires more complex coding.

Does the script run when the file is opened?

Yes, you can configure the script to run automatically when the spreadsheet is opened. In the Apps Script editor, look at the left sidebar and click on Triggers. Click the blue + Add Trigger button at the bottom right. Select showMessageBox as the function to run, From spreadsheet as the event source, and On open as the event type. Click Save.

Why does the script say "You do not have permission"?

This error usually means that the script has never been run before or that the permission token has expired. Since Apps Script runs in your browser, it needs your explicit permission to access your Google Drive and Sheets data. You must click the Review Permissions link and grant access for your specific account.

Can I pass a cell value into the message box?

Absolutely. You can modify the function to accept a variable. For example, function showMessage(cell) { SpreadsheetApp.getUi().alert(SpreadsheetApp.getActiveSpreadsheet().getRange(cell).getValue()); }. Then, when assigning the script to a button, you would pass the cell reference like showMessage("A1") or showMessage("B2").

Is there a limit to how long the text can be?

There is no hard character limit, but extremely long strings may wrap awkwardly in the browser window or cut off depending on the screen size of the user's device. It is best practice to keep the message concise and informative to ensure it is readable by everyone.

Can I use this on mobile devices?

Yes, if you open the Google Sheets app on an Android or iOS device, the script editor is accessible via the Extensions menu. The same code works, and the message box will appear in the mobile browser or app interface, provided the user has granted the necessary permissions.