How to apply a button to clear specific cells in Excel?
Normally, you can hold the Ctrl key to select multiple specific cells, and then clear the cell contents as you need. If you are always need to clear these specific cells time to time, you can create a clear button to clear them with just one click. In this article, I will talk about how to create a clear all button to clear some specific cell contents.
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
First, you should create a shape button, and then apply a code, at last, tie the code to the shape button. Please do as follows:
1. Click Insert > Shapes > Rectangles to select the Rectangle shape, and then drag the mouse to draw a rectangle button in anywhere of the sheet as you need, see screenshot:
2. Then input the text and format the shape button as you need, see screenshot:
3. And then you should insert the VBA code, please hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Clear cell contents from specific cells:
Sub Clearcells() 'Updateby Extendoffice 20161008 Range("A2", "A5").Clear Range("C10", "D18").Clear Range("B8", "B12").Clear End Sub
Note: In the above code: A2,A5 indicate it will clear the cells in the range A2:A5, not just the two cells individually, you can add multiple ranges, such as Range("B8", "B12").Clear script within the code to clear.
4. Then save and close the code window, and then link the code to the shape button, right click the button, and select Assign Macro, in the Assign Macro dialog box, choose the Clearcells code name from the Macro name list box, and click OK button to exit this dialog. See screenshot:
5. And now, when you click the Clear All button, the specific cells you defined are cleared at once, see screenshot: