Learn to add a Clear Content Button in Excel with the help of VBA code to Clear Contents of a specific range. Simplify your tedious jobs and save time.
Usually, we need to do many tasks repeatedly while creating spreadsheets in Excel. These include clearing cells, deleting ranges, printing ranges, etc. You can automate these tasks with the help of VBA in Excel.
Here, we will learn how to insert a command button to Clear Contents of a specific range in Excel.
Steps to Insert Clear Content Button in Excel Using VBA
5 Easy steps to insert Clear Content Button in Excel:
- Go to the Developer tab.
- Click on Insert in the Controls tab. Under ActiveX Controls, select Button. Draw the button at your desired location. Configure the button.
- Right-click on the button and select View Code. The Visual Basic window will open.
- Copy and Paste the code.
- Click on the Save icon and close the Visual Basic window.
Let’s understand it with the help of an example.
Given below is an example of weekly attendance:
In this data, the dates, days, and attendance section changes every week. Thus, to automate this process insert a formula for date and weekday. To clear the attendance section markings present/absent, we will insert and configure a Clear Content Button.
Go to Developer Tab and Click on Insert. Select the ActiveX control button. Draw the button beside the data and configure it.
To configure the button right-click the button and select Properties. You can rename the button by changing the caption. To change the fonts click on three dots at the end of the Fonts as shown in the figure below:
Now, Right-click on the button and select View Code. The Visual Basic window will open.
Copy and Paste the following between the code:
Click on the Save icon and close the Visual Basic window.
Important Note: The C5: H12 is our range here. You can type in your desired range in the code.
That’s it. The Clear Content Button now clears the data from C5:H12 as shown in the image above.
Click the link below to download the sample file:
If you like this article, kindly share it on different social media platforms so that your friends and colleagues can also benefit from the same. Sharing is Caring.
If you have any queries or suggestions please share them in the comment section below. We will be more than happy to assist you.