How to Insert a Clear Content Button in Google Sheets

Video google sheet button to clear cells

Wouldn’t it be amazing if there was a way to simplify the tedious tasks of deleting cells, removing ranges, and printing ranges in Google Sheets? Well, the good news is that you can automate these tasks using App Script in Google Sheets. In this article, we will learn how to insert a clear content button in Google Sheets using App Script.

Steps to Insert a Clear Content Button in Google Sheets using App Script

Here are the four easy steps to add a clear content button in Google Sheets:

  1. Open App Script.
  2. Copy and paste the code for the ClearCell function into App Script.
  3. Draw a button.
  4. Assign the App script to the button.

Let’s dive into each step in detail with an example.

Example

Consider the following weekly attendance data:

Clear Content Button Google Sheet

  1. Go to the Extensions menu and select Apps Script.

Apps Script Google Sheet

  1. The following window will open:

App Script

  1. Select everything and delete it. Then, copy and paste the code below into the script:
function ClearCells() {
   var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
   sheet.getRange('B4:G11').clearContent();
}

Make sure to insert the correct sheet name and range according to your needs. For example, our sheet name is Sheet1 and the range is B4:G11.

  1. Go to the Insert tab and select Drawing.

Insert Button GS

  1. The following window will appear:

Button Google Sheet

  1. Draw the button using the Text function. Give it a name and format the color, fonts, size, and background according to your preferences.

  2. Place the button on the sheet at the desired location. Right-click on the button and click on the three dots to open the following dialog box:

  3. Select Assign script from the menu and insert the script name as ClearCells.

App Script

Your clear content button is now ready to be used. By clicking on the button, you will get the following result:

Clear Content Button Google Sheet

Click here to download the example file.

In addition, you can also download human resources templates such as the Excel salary slip template for India, the payroll format for the UAE, a simple salary sheet, and an employee salary sheet from our website.

If you found this article helpful, feel free to share it on various social media platforms so that your friends and colleagues can benefit as well. Sharing is caring, after all!

Related posts