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

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

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


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
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.
    Robin · 18 days ago
    Hi! Works great for me with this code as you mentioned:

    Sub Clearcells()
    Range("A2", "A5").ClearContents
    Range("C10", "D18").ClearContents
    Range("B8", "B12").ClearContents
    End Sub

    However, I want to keep the number "0" or the procentage "0" for certain cells. Also, keep the previous selected colour. The reson for this is I use these cells as input cells and want to use the buttom to clear certin input cells.


    Thanks in advance!
  • To post as a guest, your comment is unpublished.
    hk Walasey · 2 months ago
    Please give marco for clear if cell content less than 4 digital numbers. Thanks
  • To post as a guest, your comment is unpublished.
    jorge · 3 months ago
    when the command button I press delete it also deletes the continuous cells and I already have a formula in them and I don't want to delete those
  • To post as a guest, your comment is unpublished.
    Arshpreet · 3 months ago
    its not working
  • To post as a guest, your comment is unpublished.
    NOCKTYS · 5 months ago
    How to do on Google Sheets please ?
  • To post as a guest, your comment is unpublished.
    Fabricio · 5 months ago
    It is not working on merged cells. :(
  • To post as a guest, your comment is unpublished.
    LJ Majik · 7 months 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.
      Don · 5 months ago
      you can use = clear.


      for Eg.

      Range("A2", "A5") = Clear
  • To post as a guest, your comment is unpublished.
    Jennifer · 7 months 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 · 6 months 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 · 1 years 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 · 1 years 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 · 1 years 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 · 1 years 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 · 1 years 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.
  • To post as a guest, your comment is unpublished.
    Basil Rubber Factory · 1 years ago
    This is clearing the border also, what can i do?
    • To post as a guest, your comment is unpublished.
      Jay · 1 years ago
      change clear to clearcontents then formatting will stay the same after clearing. only text will be gone not borders and colouring etc
  • To post as a guest, your comment is unpublished.
    ian · 1 years ago
    can you make this work over several sheets?
  • To post as a guest, your comment is unpublished.
    Piotr · 1 years ago
    Thx for this code. How to clear cell contents or ideally fill it up with 0 value in a protected sheet with just few editable cells? Thx for help on ot.
    • To post as a guest, your comment is unpublished.
      Robert · 1 years ago
      Instead of the clear command, an example line from above would look like:
      Range("A2:A5") = 0
  • To post as a guest, your comment is unpublished.
    Ashleigh Bonner · 2 years ago
    Thank you so much for this information!!

    Another tip: I added a textbox. To combine the textbox with the shape, I selected the textbox, held down SHIFT, and then selected the shape. With those both selected I right-clicked and selected GROUP, then GROUP, again.

    When these are grouped, you can still change the text and other formatting.

    To ungroup, just right-click your new button and select GROUP > UNGROUP.
    • To post as a guest, your comment is unpublished.
      Calvin Hodgson · 1 years ago
      Or, simply right-clicking the shape allows you to change formatting and text.
  • To post as a guest, your comment is unpublished.
    Steph · 2 years ago
    thank you!
  • To post as a guest, your comment is unpublished.
    ken besse · 2 years ago
    This also clears any formatting of the cell. How doI do this if I wantto keep formulas and formatting suchace as shading or borders
    • To post as a guest, your comment is unpublished.
      Adam · 2 years ago
      change the command from "clear" to "clearcontents" to just erase the text inputs
  • To post as a guest, your comment is unpublished.
    anand · 2 years ago
    GIVE FORMULAS FOR SAVE AND CLEAR