Description:
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
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
Instructions:
- 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
Conclusion:
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.
Please note that there is a typo in your code above; ClearContents is used for both examples.
The first instance should read:
Range(“A1:C10”).Clear
The second instance is correct as:
Range(“A1:C10”).ClearContents
Thanks Dave! Corrected it!
Regards,
PNRao
Hi!
I want to erase some of the contents but not all from cells. For example in every cell I have several qualifiers with an specific value, something like /qualifier1=value2 /qualifier2=value2 etc. I just want to erase all qualifiers but number 1. Is this possible?
Thank you in advance!
Hi Felipe,
There is no direct method/finction to do this task. You can write a formula or VBA procedure to do this.
Thanks-PNRao!
hello sir
Can we clear excel data of two excel sheet of specific cell’s in one code
e.g. i have two excel sheet in my workbook A and B and i wont clear data of specific cell using range option (A3:B10) for Sheet A and (C2:D10) for sheet B, i want this operation in One code only
can you please help me
Regards
Dushyant Padhya
If you want clear multiple ranges from a sheet with one single clear statements, you can use the below method:
If I am correct, you want to put tow statements in one single statement:
Below is the code to clear the two ranges:
You can use “:” to concatenate the VBA statements
Hope this hellps!
Thanks-PNRao
I have a list where some cell values begin with a letter and some with a number. How can I use the clear function to clear cells beginning with a letter but leave those beginning with a number? All cells contain both letters and number, but I want to clear those where the letter is the first character. also some are uppercase and some lowercase (not sure if this matters)
thanks
James
Hi James,
The below macro checks for the first character of each cell in a given range, and clears if it is non-numeric:
Thanks-PNRao
I want to get the data from one workbook to another workbook by using VBA coding. So could you please help me.
Hi Ravindra,
You can use the Copy command as shown below:
Thanks-PNRao!
Hi and thanks in advance.
I have a List of 3 items per row in a Worksheet with 30 such rows and a button besides each to run a Macro to clear the contents when required.
Other macros perform functions on the data in the lists.
Unfortunately I am using the .ActiveCell which doesn’t seem to detect I am in the Cell with the button but is uses the last cell I was in, any ideas on how I can clear the contents of the 3 cells beside the buttons without writing 30 different macros?
If I want to clear a variable range of cells based on a specific input how would I do this?
for example lets say i am running a code that fills cells e5:e10 based on an input variable that i have chosen. then i decide that i want to change that input variable and by changing it my data range runs from cell e5:e9. however because i just ran a calculation that created a range from e5:e10 the value in cell e10 is still present with the new range ( i want to the contents in cell e10 to be cleared)….i hope this wasn’t too confusing.
I want to clear the data without formulas from active worksheet
Please help…
Hi Venkat, You can use Activesheet.Cells.Clear Method to clear the entire sheet (Activesheet).
Thanks-PNRao!
Hello Everybody,
I want clear particular range of data from cells.
For example: Cells which have only zero and the value above 5000 from the whole sheet.
Can u suggest me how to give coding.
how to use check box to clear and unclear cell
We can use .Clear Method to clear the Cells but, we can do not have the method to undo /unclear the cleared cells:
The below Code will clear when you select the check box.
Thanks-PNRao!
Hi..
I’m new to macro programming
How to write a macro with relative refrences which can clear/clear contents after a particular cell. That is if a cell is chosen and macro is started it should delete the values or formats for the given no ( say 12) cells .May be row or columnwise.
I have one workbook with several sheets, (more than 200 sheets) and I would like to clear contents within specific cells (same on all sheets) in workbook. How can I do that each sheet is named with last 4 digits of each VIN.
What code would I use?
hi
I want to this macro code
one excel sheet first cell to six cells type “p” letter then seventh cell automatic display “wp”
please tell me this vba code
Hi,
Is there any way to clear data of selective rows from multiple sheets keeping the formatting and formula same??
Thanks
Himani
Hi Anas,
I have the exact same query – it’s very tricky.
did you end up finding a solution?
Thank you PNRao for everything thus far!
I want to clear the values that are returned in a range of cells but, I want to keep the formula that was entered in the cells. Is there a way to do that?
Hello,
How can I clear content of multiple tabs? For example I need to clear Range(“A:N”) columns from 5 different worksheets
hi every body I do have a excel template, and I do have a program for clearing data but I also want to add an option whether to clean the data , ie yes no option if the user press the no button the data will not be cleared can u tell me a command for that case. could you pleas send me a mail
thanks for your cooperation
Hello All,
Need help on one thing, Whenever i open Excel which containing macro an error occurs as “Security Warning Macro have been Disable. Enable Content” . After clicking on Enable content button the excel open in good manner.
Now I have to disable any cell value or change color to while, let say cell F5 having text “Best of Luck” which is in black color. I record the macro as to change it to white color/it should be disabled. OK.
My Question is, whenever we click on Enable content button, the text color “Best of Luck” of cell F5 should be change to white/ disappear.
So How to do, need help.
Hello Dear,
I need some help from you. I want to delete entire sheet content.But only content that filled up not content that created by formula.
I need to figure out how to clear a set of rows underneath my header row. e.g. HeaderRow+1, (Don’t know what to put here). Clear Contents.