Hi everyone, in this article, we will learn about how to make a button in google sheets.
We interact will many applications in our day-to-day life and using that application we click many buttons to do things. So, we understand the importance of buttons in the user experience, in google sheets, we can have buttons for performing certain actions just like we have an HTML button tag that adds a button on a web page and then is programmed by JavaScript. Similarly, we add a button in our google sheets file and program it using AppScript or Macro. This article focuses on creating buttons and assigning them the functions to perform.
Use case of a Button in Google Sheets
As we have App scripts and Macros, they help us automate google sheets. But we have to manually go into the extension tab to run a macro or script, although we have shortcuts for that purpose still, the buttons are more interactive.
What if we could add certain buttons, custom design them and give them unique functionalities to perform when clicked? Sounds interesting, this is why we need to learn how to make a button in google sheets. Buttons increase the overall experience of users on our document, they enhance the design aesthetics of the overall document, and of course, they give quick performance clicking on a button will instantly perform the specified action. These are some reasons we need to learn how to make a button in google sheets.
How to Make a Button in Google Sheets
Now we will see the steps included to make a button in google sheets. We have two methods to add buttons (in fact three methods, but only two are recommended and used widely). So we will learn each method step-by-step. Let’s move on to the methods. Why do we need to learn – How to Make a Button in Google Sheets?
How to Make a Button in Google Sheets – By Inserting an Image
In this first section, we will learn how to make a button in google sheets by inserting an image, an image should be a vector image, and must have a transparent background (any image can be added but to make a button we must take care of these two things). We will add an image in this method and will also see how to assign an App Script function to this button let’s move to the steps required to do this.
Step 1
Some sample data to ensure the function is working accurately
Step 2
Select any empty cell
Step 3
Go to Insert > Image > Insert an image over the cell
Step 4
Click on browse, or you can drag and drop the file.
Step 5
Pick an image and select it from the directory
Step 6
Your image is added, and you can resize, and move it anywhere freely.
How to Make a Button in Google Sheets – Assign a Script to Image
Since the image is added, now we need to assign a script to the image. For that simply follow the below steps
Step 1
Right-click on the image
Step 2
Click on three dots on the top right corner
Step 3
Now you need a script to assign it to an image, I will provide the script below you can copy and use it for your practice.
Step 4
From the available options, click on “Assign a script”
Step 5
A pop-up will appear
Assign script
What script do you want to assign?
In the below text box Write your app script name and click the OK button
Step 6
The script is assigned to your button now click the button and see the function will be performed automatically
The Script used in this example is
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet();
var range = ss.getRange(1, 1, ss.getMaxRows(), ss.getMaxColumns());
range.clearFormat();
}
This script simply resets the default formatting.
How to Add Script Code to your Google Sheets File
Step 1
Copy the code
Step 2
Go to Sheet, Go to Extensions > Apps Script
Step 3
A code editor will open, remove all and paste the code
Step 4
Click on Save
How to Make a Button in Google Sheets using Drawing Tool
In this section we will learn how to make a button in google sheets by drawing a button using a drawing tool, the drawing tool is built-in in Google Sheets. We will use it to draw a button and will insert it into our sheets, and then similarly we will assign a script to it to perform certain actions. Let’s move on to the below steps to see how to draw a button
Step 1
Go to insert > Drawing
Step 2
An art bot will open. In the drawing tool menu, click on the shape
Step 3
Select shapes, and pick a shape from many given shapes (a rounded square is recommended)
Step 4
As you selected a shape, a drawing cursor will appear, drag it and draw the body of the rounded square.
Step 5
After the outline, you need color. Select your shape and go to Fill color
Step 6
Select Gradient
Step 7
Pick any gradient you like; your gradient will be added.
Step 8
Now you need the text (the button name), select the shape, and click on a text box in the tool menu
Step 9
Now inside your shape draw a text box under the shape.
Step 10
Write your text
Step 11
Center align the text box and the text
Step 12
Click on save and close and your button will be added to your sheets
As you have done with the drawing of the button, now you can assign the script similarly as we assigned to the image we used in the previous method.
Let’s see it briefly for the button as well
Step 1
Right-click on the button and click on 3 dots on the top right corner
Step 2
Click on assign a script
Step 3
Add the script name and click on the Ok button
Step 4
Now verify by clicking on the button
This is how you do it, we have learned two methods to add buttons in google sheets, you can also use one more method but that is not user friendly and that’s why I did not include in this article the method is “insert an image in the cell” because it does not give you the flexibility to move and resize the image.
Download/Copy Free Google Sheets Template
How to Make a Button in Google Sheets
Notes
- Always remember to add the image over cells, not in the cell
- Adding an image in the cell is not used, because it bounds your image inside a cell and it cannot be resized or moved in any way.
- Always try to keep the buttons less colorful using light gradients instead of solid colors
- You can assign any kind of script to the button; the script function will be assigned to the button.
- The button you draw, can take any kind of script and perform a specific function for you
- Always add a transparent image as a button to look more professional
- The name of your project is not your script name, many beginners get confused about it, your script name is the name of the main function written in the script.
FAQs
How to add an image as a button in google sheets?
You can add an image to your google sheets as a button by going to insert > image > insert image over cells. Select the file from the options, Upload, Camera, URL, Photos, Google Drive, Google image search, use upload and upload your image on the sheets, then right click on the image on the three dots to find more options, now find the option assign a script and it will ask the name of the script, provide the name and click on the Ok button.
How to draw an image as a button in google sheets?
You can go to insert > drawing to go into the drawing interface, in the drawing tool you have several options, select a starting shape and make the outline of the button, it can be circled, square, rounded square, or of any common shape, now assign some colors (gradient recommended). then you need to add the text (button name), add a text box from the toolbar and draw a box, write the text and when you’re done click on save and close, and the button will be added to your sheets. Now, right-click and click on three dots to open more options, find the options “assign a script” click on it and it will ask for the name of the script provide the name, and click the Ok button.
I don’t know my script name? how can I find it?
Your script name is the name of the function that appears on the top menu before the “Execution log”. You can find it on the first line after the function keyword.
Conclusion
Wrapping up how to make a button in Google sheets, we have learned about the buttons in every detail, in the above introductory sections, we have seen what are buttons and why they are important? Then, we discussed the two best methods to add images in your google sheets file as a button then we saw how to assign the app script code to those buttons and verified the buttons are working perfectly, and we have seen how to draw a basic button in google sheets drawing tool.
I hope you have enjoyed this article and found it useful, please don’t forget to share the article with your friends. Give a like and share your thoughts below in the comment section. That’s all from how to make a button in google sheets, will see you very soon in the next article till then take care. Keep learning with Office Demy.