How to Clear Contents Without Deleting Formulas Using VBA in Excel: 4 Methods

Method 1 – Clear Contents from Range Without Deleting Formulas Using VBA in Excel

STEPS:

  • Go to the Developer tab and select Visual Basic. It will open the Visual Basic window.
  • Press the Alt + F11 keys together to open the Visual Basic window.

Clear Contents from Range Without Deleting Formulas Using VBA in Excel

  • Cclick on the View tab of the Visual Basic, a drop-down will appear.
  • Select Immediate Window from there.
  • Press the Alt + G keys to open the Immediate window.

  • Place the cursor in the Immediate Window.

  • Type the code below in the Immediate Window:
Sheet2.Range("B5:F11").SpecialCells(xlCellTypeConstants).ClearContents
  • Place the cursor at the end of the code and press Enter.

Clear Contents from Range Without Deleting Formulas Using VBA in Excel

Change the sheet number and range according to your needs. Cclear contents from the range D5:G10 in Sheet 5. Type the below code:

Sheet5.Range("D5:G10").SpecialCells(xlCellTypeConstants).ClearContents
  • Clear the contents without deleting the formulas.


Method 2 – Insert VBA to Remove Contents from Selection Without Erasing Formulas

STEPS:

  • Select the cells from where you want to clear the contents. We selected cells C5 to F9.

Insert VBA to Remove Contents from Selection Without Erasing Formulas

  • Press Alt + F11 to open the Visual Basic window.
  • Press Alt + G to open the Immediate Window.
  • In the Immediate Window, type the code below:
Selection.SpecialCells(xlCellTypeConstants, 23).Clear
  • Place the cursor at the end of the code.

Insert VBA to Remove Contents from Selection Without Erasing Formulas

  • Hit Enter to see results like the picture below.


Method 3 – Apply Excel VBA for Contents Omitting from Entire Sheet Without Deleting Formulas

STEPS:

  • Navigate to the Developer tab and select Visual Basic. It will open the Visual Basic window.
  • Press the Alt + F11 keys together to open the Visual Basic window.
  • Press Alt + G to open the Immediate Window.
  • In the Immediate Window, type the code below:
Activesheet.cells.SpecialCells(xlCellTypeConstants, 23).Clear
  • Place the cursor at the end of the code.

Apply Excel VBA for Contents Omitting from Entire Sheet Without Deleting Formulas

  • Hit Enter to see results like the picture below.


Method 4 – Clear Contents from Workbook Without Removing Formulas Using Excel VBA

STEPS:

  • Press Alt + F11 to open the Visual Basic window.
  • Hit Alt + G to open the Immediate Window.
  • Type the code in the Immediate Window:
For Each wks In Worksheets: wks.Cells.SpecialCells(xlCellTypeConstants, 23).Clear: Next wks
  • Place the cursor at the end of the code.

Clear Contents from Workbook Without Removing Formulas Using Excel VBA

  • Press Enter to clear contents from the whole workbook.

Download Practice Workbook

You can download the practice book from here.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Mursalin Ibne Salehin
Mursalin Ibne Salehin

Mursalin Ibne Salehin holds a BSc in Electrical and Electronics Engineering from Bangladesh University of Engineering and Technology. Over the past 2 years, he has actively contributed to the ExcelDemy project, where he authored over 150 articles. He has also led a team with content development works. Currently, he is working as a Reviewer in the ExcelDemy Project. He likes using and learning about Microsoft Office, especially Excel. He is interested in data analysis with Excel, machine learning,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo