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
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.
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:
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)
Clearing Entire Worksheet using Clear Method
This method will clear entire worksheet including formats.
Clearing Only Data from Worksheet using ClearContents Method
This method will clear only data of worksheet, not formats.
- 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.