Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

 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.

Apply a button to clear specific cell contents with VBA code

Excel Productivity Tools

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 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial


arrow blue right bubble Apply a button to clear specific cell contents with VBA code

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:

doc button clear cells 1

2. Then input the text and format the shape button as you need, see screenshot:

doc button clear cells 2

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:

doc button clear cells 3

5. And now, when you click the Clear All button, the specific cells you defined are cleared at once, see screenshot:

doc button clear cells 4


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 80% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    LJ Majik · 8 days ago
    Is there a way for me to keep the data validation list drops on the cells. For example my list drop includes Yes or No and I would like to reset the cells to blank but keep my data validation in the background
  • To post as a guest, your comment is unpublished.
    Jennifer · 24 days ago
    Hi,

    What code do I use if I only need to clear one single cell instead of a range of cells?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 days ago
      Hi, Jennifer,
      To clear only one cell, you just need to change the VBA code as this: (Note: change the cell A2 to the cell you want to clear)

      Sub Clearcells()
      Range("A2").Clear
      End Sub

      Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Radheshyam · 6 months ago
    simply I did same in worksheet it worked when I protect the sheet it shows error 1004, any suggestion in this case?
    • To post as a guest, your comment is unpublished.
      skyyang · 6 months ago
      Hi, Radheshyam,
      To run above code in a protect worksheet, please apply the below code: (Note: change the text "password" to the password which protect your sheet)
      Sub ClearcellsAsProtect()
      Dim xWS As Worksheet
      Dim xPsw As String
      Set xWS = ActiveSheet
      xPsw = "password"
      On Error Resume Next
      xWS.Unprotect Password:=xPsw
      Range("A2", "A5").Clear
      Range("C10", "D18").Clear
      Range("B8", "B12").Clear
      xWS.Protect Password:=xPsw
      End Sub

      Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Stan · 9 months ago
    I have a workbook with 11 tabs, plus one at the beginning marked as "Start Here". I want to create one button in that tab that will clear up to 9 individual cells of it's contents, or enter a "0" in it within each of these tabs. The cells I want to clear do not necessarily reside in the same spot on each page. Is this possible and how is it done? I presume this can be done in VisualBasic, but would it be easier for a neophyte to create it using Macros?
  • To post as a guest, your comment is unpublished.
    Adnandos · 11 months ago
    Hi. What is the best way to create seperate buttons to clear the contents of each row separately? eg data capturer is happy with the inputs of every other row, but then needs to clear rows 3, row 6 and row 7. What's the most efficient way to create buttons to clear in this way, ie row only?
    • To post as a guest, your comment is unpublished.
      OS · 6 months ago
      Hi, Put a button on top of row 3,6,7. Assign the same marco as above on each button to clear that particular row only.