Computer >> Computer tutorials >  >> Software >> Office

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

This is the sample dataset.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Step 1 – Creating a VBA Module to Clear Cells in Excel

  • Go to the Developer tab and click Visual Basic.

You can also press ALT + F11 to open the “Microsoft Visual Basic for Applications” window.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • In “Insert”, select “Module’”.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Step 2 – Inserting a VBA Code in the Module

  • In the“Module” window, enter this VBA code.

Code For Clearing Cells Keeping the Format:

Sub Clear_Cell_With_Button()
Dim rng As Range
Set rng = Application.InputBox(Prompt:="Select the Range of Cell", Title:="Exceldemy", Type:=8)
rng.Select
Selection.ClearContents
End Sub

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Code For Clearing Cells including Format

Sub Clear_Cell_With_Button_including_Format()
Dim rng As Range
Set rng = Application.InputBox(Prompt:="Select the Range of Cell", Title:="Exceldemy", Type:=8)
rng.Select
Selection.Clear
End Sub

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Code For Deleting Cells 

Sub Delete_Cell_With_Button()
Dim rng As Range
Set rng = Application.InputBox(Prompt:="Select the Range of Cell", Title:="Exceldemy", Type:=8)
rng.Select
Selection.Delete
End Sub

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Read More: Excel VBA to Clear Contents of Range

Difference Between Clear, Delete, and ClearContents Command in Excel VBA

The ClearContent command only clears the cell value while keeping the cell format. The Clear command removes both cell value and cell formatting and leaves the cells blank. The Delete command removes the cells and shifts the bottom cells up.

Step 3 – Create a Button to Clear Cells in Excel

  • Go to the Developer tab.
  • Click Insert and select Button.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • Draw a box in the area you want to place the button.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • The  “Assign macro” window will open.
  • Select the macro you created.
  • Click OK.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • You will see a macro button in the selected area. Right-click the macro button to rename it as “Clear Contents Only”.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • Create two more buttons for the other codes named “Clear Cells Including Format” and “Delete Cells

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Step 4 – Running the VBA Macro to Clear Cells with a Button

  • Click “Clear Contents Only” to clear the selected cell values only.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • A window will open. Select the range and click OK.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • The selected cell values are cleared but the format is the same.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • Click “Clear Cells Including Format” to clear cell values and remove formatting.
  • Select the cell range that you want to clear and click OK.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

The selected cells are cleared.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

  • Click “Delete Cells” and select the cell range.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

The selected cells are removed and the bottom cells are shifted up.

Easily Clear Excel Cells with a One‑Click Button: 4 Simple Steps

Read More: How to Clear Contents of a Sheet with Excel VBA

Download Practice Workbook

Download the practice workbook here:

Related Articles

  • How to Clear Contents Without Deleting Formulas Using VBA in Excel
  • Excel VBA to Clear Contents of Named Range
  • Excel VBA to Delete and Shift Left Any Cell or Column
  • Excel VBA: Clear Contents If Cell Contains Specific Values
Get FREE Advanced Excel Exercises with Solutions!