How to Insert Button in Google Sheets (5 Quick Steps)

Often we need to use specific scripts or macros continually in Google Sheets or Excel. Inserting a button and assigning those scripts or macros to that button helps to get rid of the frequent use of those scripts or macros. In this article, we have demonstrated the easiest step-by-step procedure to insert a button in Google Sheets. The result of our example may look as follows eventually.

overview of making button in google Sheets


A Sample of Practice Spreadsheet

You can download the spreadsheet used to describe methods in this article from here.


What Is Button in Google Sheets?

A button in Google Sheets is basically used to perform a specific task by assigning a Script. Like, here we’ll create a button to calculate the average.


Uses of Button in Google Sheets

The adaptable controls known as Button comes in handy in a variety of situations. You can use button if you want-

  1. Data should be submitted to one or more data sources.
  2. Give users the option to change the form’s view.
  3. Update information from a backup data source.
  4. Delete any questioned information from the form.
  5. Compute the information on the form.

Step-by-Step Guide to Insert Button in Google Sheets

We will be using the following worksheet to describe the procedure to insert button in Google Sheets. The dataset represents some students’ grades in Maths and Physics. What we want to do here is to add a button that will contain a script which will calculate the average marks in those 2 subjects with just a click on the button.

dataset to Insert Button in Google Sheets


Step 1. Inserting Image or Shape

We can add a button in Google Sheets in two ways. By inserting an image then linking it with the script or by drawing a button manually using the drawing menu from the toolbar then linking it with the apps script.


1.1 Using Image Option

Let’s think, we want to add a button by inserting an image. You can add any image you want as a button. We will be using the following image here.

image to insert as a button

Steps:

  • First, click on the Insert menu at the toolbar, go to Image and then select Insert image over cells.

inserting image by using the toolbar

  • The following window will appear. Click on Browse.

browsing image from drive

  • Insert the image file from the location you saved it.

selecting the image to insert button in google sheets

  • Or simply drag the image file thereby holding it with your left-mouse button. You can also copy the image file and paste it there.

dragging image to insert button in google sheets

  • The image will appear on your worksheet as follows.

button image on the spreadsheet


1.2 Using Drawing Menu

Instead of inserting an image, we can create a button by drawing it manually using the Drawing tool from the toolbar.

Steps:

  • First, go to the Insert menu at the toolbar then choose Drawing.

using drawing tool from the toolbar to insert button in google sheets

  • A new window as follows will appear on your screen.

window of drawing tool appeared in google sheets

  • Assume, we want to create a rectangular-shaped button here.
  • Click on the Shape ribbon, click on Shapes then select Rectangle.

selecting the shape to insert as button in google sheets

  • Draw a rectangle and then give it a name as you want by left-clicking twice on that rectangle.
  • You can customize font size, font type, fill color of the drawing as well. Here, I have set the text size to 20, chosen the font type as “Lobster” and filled the rectangle with green color.
  • After completing the drawing, click on Save and Close.

modifying the shape of the button

  • Following this, the rectangular drawing for a button will appear on your screen.

drawing of the button on the spreadsheet

Read More: How to Insert Video in Google Sheets (2 Easy Ways)


Step 2. Resizing Button

Resize the inserted image or the drawn button using the Square icons on the corner and the sides of the button. Here, I have illustrated the method using the image I have inserted.

resizing the image or the drawing to insert button in google sheets


Similar Readings


Step 3. Inserting Script

  • Now, at the top of your toolbar, select Extension then choose Apps Script.

opening apps script window from the extensions menu at the toolbar

  • A new tab of Apps Script will come up in your browser.
  • Insert the codes given below in the gs section there then click on the Save ribbon. We will use it to calculate our required average values then to get the output in Cell C17 and Cell D17.
function calculateAverage() {
var wannagetavg = SpreadsheetApp.getActiveSpreadsheet();
//var sheet = wannagetavg.getSheets()[0];
var feuille = wannagetavg.getActiveSheet();
var cell = feuille.getActiveCell();
//var columnwiseavg = 4;
var columnwiseavg = wannagetavg.getRange("C17");
columnwiseavg.setFormula("=AVERAGE(C5:C16)");
var columnwiseavg = wannagetavg.getRange("D17");
columnwiseavg.setFormula("=AVERAGE(D5:D16)");
for(var i = 1;i <= columnwiseavg;i++)
{
feuille.insertRowAfter(2);
}
}

inserting the code in the apps script section then saving the code

 

  • Click on Run at the toolbar there.

running the code for further execution

  • Authorization will be required to follow the given codes. The following window will appear on your screen. Select Review permissions.

authorization tab appeared as a safety window

  • You will be asked for an email. Here, I have selected mine.

selecting email address to proceed forward

  • After selecting the email address, a safety page will appear on your screen. Select Advance from there.

safety window again. selecting advanced option from there

  • Next, select “Go to Untitled project (unsafe)” from the newly appeared window.

going forward using the unsafe untitled project option

  • Following this, press on Allow.

allowing to run the script properly

  • Something as follows will appear in the Execution bar that is in the below of the Apps Script.

execution log result appeared

Read More: How to Insert Formula in Google Sheets for Entire Column


Step 4. Assigning Script

At this point, we have to assign the script previously inserted in the Apps Script menu to the button.

  • Select the image then click on the 3 dots menu ribbon as shown below. After that, click on Assign script.

assigning script to the button in google sheets

  • Type down the function name “calculateAverage” we have given in our script then click on OK.

typing or inserting the function name of the script

Read More: How to Insert an Exponent in Google Sheets (3 Easy Ways)


Step 5. Using the Button

  • Simply left-click just once on the created button. First, it will return a message “Running Script” as follows.

clicking on the button to run the script in google sheets

  • Finally, the message “Finished script” will appear and the output will return as follows in Cell C17 and Cell D17.

return of the output in the specific cells

Read More: How to Insert Equation in Google Sheets (4 Tricky Ways)


How to Make a Hyperlink Button to Jump to a Specific Sheet in Google Sheets

We can add a hyperlink button to jump to a specific sheet in Google Sheets. Presume, we want to create a hyperlink button in the following dataset that will take us to the sheet titled “Sheet1” instantly.

dataset to Make a Hyperlink Button to Jump to a Specific Sheet in Google Sheets

Steps:

  • Create a button by inserting an image or by drawing a shape using the Drawing tool from the toolbar then resize it using the Fill handle icons along its corners and sides just like previously.

inserting image or drawing to set that as button

  • Next, at the toolbar, click on the Extension menu then select Apps Script.

opening apps script window using extensions menu from the toolbar

  • We will use the following script below that will take us to “Sheet1” after clicking on the button.
function JumptoSheet() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'), true);
};
  • But, if there exists a code in the gs section already, then click on the Add a file plus icon (+) ribbon then select Script.

adding new script section to add code to jump to a specific sheet in Google Sheets

  • Insert the codes in the newly created “Untitled.gs” section then click on Save.

inserting the code

  • Now, get back to your spreadsheet, select the button image/draw then click on the 3 dots menu ribbon as shown below. After that, click on Assign script.

assigning the new script to the button in google sheets

  • Type down the function name “JumptoSheet” we have given in our script then click on Ok.

inserting function name

  • Now, simply left-click once on the created button. First, it will return a message “Running Script” as follows.

activating script by clicking on the button

  • Finally, following this will take you to Sheet1 and the message “Finished Script” will appear as follows.

jumps to the specific sheet


Conclusion

The article contains the step-by-step process to insert button in Google Sheets. Hope, this will definitely help you with your task. Visit our site officewheel.com to see more related articles.


Related Articles

Adrey

Adrey

Hello! This is Raiyan Zaman Adrey, a fresh graduate in BSc in Civil Engineering from Bangladesh University of Engineering and Technology. From my high school I have been using Excel in which I was always interested and had fun and this led me to do more research on Excel and Google Sheets as both are kinda similar platform. I have always been enthusiastic, self-motivated, reliable and hard working person and for a long time, I am trying to improve myself more and more so that I can face any challenging situation and adapt myself to any environment.

We will be happy to hear your thoughts

Leave a reply

OfficeWheel
Logo