Most of the times we clear the data from a cells or a range and re-enter to do some calculations. For examples we may have some template to enter data and calculate the tax. We may want to do this for all the employees of an organization. In this case we need to Clear data Excel from a Range in Worksheet using VBA before entering the data for each employee
50+ Project Management Templates Pack
Excel PowerPoint Word
Advanced Project Plan & Portfolio Template
Business Presentations Templates Pack
20+ Excel Project Management Pack
20+ PowerPoint Project Management Pack
10+ MS Word Project Management Pack
Clear Cells in Excel of a range or Worksheet using VBA- Solution(s):
We can clear Cells or a Range using Clear Method OR ClearContents Method of a Range or Cell. Clear will Clear the data and Formats of the given Range or Cells. And ClearContents will clear only the data, will not clear any formats.
Clear Cells Range data in Excel Worksheet using VBA – An Example
The following examples will show you how clear the data of Cells, Range or entire worksheet using Clear and ClearContents Methods.
Clearing a Cells/Range using Clear Method
This method will clear the range of cells including Formats:
Sub sbClearCells() Range("A1:C10").Clear End Sub
Clearing Only Data of a Range using ClearContents Method
This method will clear only clear the content or data of the range not formats (Formats remain same)
Sub sbClearCellsOnlyData() Range("A1:C10").ClearContents End Sub
Clearing Entire Worksheet using Clear Method
This method will clear entire worksheet including formats.
Sub sbClearEntireSheet() Sheets("SheetName").Cells.Clear End Sub
Clearing Only Data from Worksheet using ClearContents Method
This method will clear only data of worksheet, not formats.
Sub sbClearEntireSheetOnlyData() Sheets("SheetName").Cells.ClearContents End Sub
- Open an excel workbook
- Enter some data in Sheet1 at A1:C10
- Press Alt+F11 to open VBA Editor
- Insert a Module for Insert Menu
- Copy the above code and Paste in the code window
- Save the file as macro enabled workbook
- Press F5 to run it
Both Clear and ClearContents are useful based on your requirement. If you want to Clear only the Content, use ClearContent method. If you want Clear everything (Content and Formats), use Clear method.