sodcalculator

10 Tech How-To

How to Make a Google Sheets Button

Guide 10-37483 · Updated · Step by step

Adding a button to a Google Sheet lets you run a script (Google Apps Script) with a single click, turning repetitive tasks like sorting, formatting, or sending emails into one-click actions. This guide walks you through creating a button, assigning a script, and making it work reliably. You’ll need a Google account and a spreadsheet where you have edit access.

What You’ll Need

  • A Google account (free)
  • A Google Sheets document you own or can edit
  • Basic familiarity with the spreadsheet interface
  • No coding experience required, but you’ll copy a simple script

Step-by-Step

  1. Open your Google Sheet – Go to sheets.google.com and open the spreadsheet where you want the button.
  2. Open the Script Editor – Click Extensions in the top menu, then select Apps Script. This opens a new tab with a blank script project.
  3. Write a simple function – In the script editor, delete any default code and paste this example:
    function myButtonFunction() {
      // This example sorts the sheet by column A
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var range = sheet.getRange("A1:C10");
      range.sort({column: 1, ascending: true});
    }
        

    You can replace the code with your own task. The function name (here myButtonFunction) is what you’ll assign to the button later.

  4. Save the script – Click the disk icon or press Ctrl+S (Windows) / Cmd+S (Mac). Give your project a name like “Button Script” and click Rename if prompted.
  5. Authorize the script – Click the Run button (▶) in the toolbar. A dialog will ask for permissions. Review and accept. This step is required once so the script can access your spreadsheet.
  6. Go back to your sheet – Return to the Google Sheets tab. You’ll create the button here.
  7. Insert a drawing – Click Insert in the top menu, then Drawing. A drawing canvas opens.
  8. Create a button shape – In the drawing tool, click the Shape icon (a circle/square), choose a rounded rectangle, and draw it on the canvas. Add text by double-clicking the shape and typing, for example “Run Report”. Style it with colors if you like.
  9. Save the drawing – Click Save and Close. The drawing appears on your sheet as an image.
  10. Assign the script – Click on the drawing to select it. Click the three-dot menu that appears in the top-right corner of the drawing, then select Assign script.
  11. Type the function name – In the dialog, enter exactly the name of the function you wrote earlier, e.g. myButtonFunction. Click OK.
  12. Test the button – Click the drawing on your sheet. The script should run, and you’ll see a brief “Executing script” message. Check that your data was sorted (or whatever your script does).

Common Mistakes

  • Function name mismatch – The name in “Assign script” must match exactly, including capitalization. A typo like mybuttonfunction won’t work.
  • Forgetting to authorize – If you skip the authorization step, the button will show an error when clicked. Always run the script once from the editor first.
  • Using the wrong sheet reference – If your script uses getActiveSheet(), it will act on whatever sheet you’re viewing when you click the button. If you want a specific sheet, use getSheetByName("Sheet1").
  • Overlapping shapes – If the drawing overlaps a cell you need to edit, it can block clicks. Move it to an empty area or a corner.
  • Not saving the script – Unsaved changes in the script editor won’t be available to the button. Save before testing.

Tips

  • Use a clear label – Name the button with a verb like “Sort”, “Clear”, or “Send Email” so users know what it does.
  • Keep scripts simple – Start with one action. You can add more later by editing the function.
  • Test on a copy – If your script modifies data, duplicate the sheet first (right-click the tab → Duplicate) to avoid losing information.
  • Use relative ranges – Instead of hardcoding “A1:C10”, use getDataRange() to include all data automatically.
  • Add a confirmation dialog – For destructive actions, add SpreadsheetApp.getUi().alert("Are you sure?") at the start of your function.

Troubleshooting

  • Button does nothing when clicked – Check that you assigned the script correctly. Right-click the drawing → Assign script. Also confirm the function name is spelled exactly as in the script editor.
  • Error: “Script function not found” – This means the function name in the assignment doesn’t match any function in your script. Open the script editor, copy the exact name, and paste it into the assignment dialog.
  • Permission errors – If you see “You don’t have permission to run this script”, go to the script editor, click Run once, and complete the authorization flow. If you’re on a work/school account, an admin may need to allow Apps Script.
  • Script runs but doesn’t do what you expect – Review your code. Use Logger.log() in the script editor and check View → Logs to see what’s happening. For example, if you sorted the wrong range, adjust the range reference.
  • Button moves or resizes when you edit cells – Drawings are anchored to a cell. If you insert rows above, the button moves. To keep it fixed, place it in a cell that won’t shift, or consider using a checkbox or a menu instead.
  • Script works from editor but not from button – This often happens if the button’s assigned function is different from the one you’re testing. Double-check the assignment and ensure the script is saved.

Frequently Asked Questions

Can I make a button that doesn’t require a script?

No, a button in Google Sheets is just a drawing. To make it do something, you must attach an Apps Script function. Without a script, the button is purely visual.

How do I change what the button does?

Edit the function in the Apps Script editor. After saving, the button will use the updated code. You don’t need to reassign the script unless you rename the function.

Can I use a checkbox instead of a button?

Yes, but checkboxes are for toggling values. You can write an onEdit trigger to run a script when a checkbox is checked, but a drawing button is simpler for one-off actions.

Why does my button work for me but not for others?

Other users need at least “Viewer” access to the sheet. If the script requires permissions, they may need to authorize it themselves. If you’re using a paid Google Workspace account, an admin might restrict script execution.

Can I add a button to a mobile app?

No, the Google Sheets mobile app doesn’t support drawing buttons or running scripts from them. You can only use buttons on the web version.

Is there a limit to how many buttons I can have?

No, you can add as many drawings as you like. However, each button must have its own assigned function, and too many scripts may slow down the sheet.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →