We can use VBA to Clear only the Formats of a specific range, cells or entire worksheet. we can use ClearFormats method of Range Object. Rang.ClearFormats method will clear only the formats of the cells or range. And the data and comments will not be deleted.
Excel VBA to ClearFormats a Range – Syntax
Here is the syntax to clear the formats of a range. You can clear the formats in any range using VBA Range.ClearFormats method.
Excel VBA to ClearFormats in a Range – Examples
The below macro will show you how to clear the formats in a range using VBA. In this example, we are clearing the formats of range “A2 to D10” using VBA.
Sub VBA_Clear_Formats_Range() Range("A2:D10").ClearFormats End Sub
Excel VBA to Clear Formats in a Range – Instructions
Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:
- Open an Excel Workbook from your start menu or type Excel in your run command
- Enter some data in any cells in range “A10 to D10” to test this macro. Also format some cell to test this macro.
- Press Alt+F11 to Open VBA Editor or you can go to Developer Table from Excel Ribbon and click on the Visual Basic Command to launch the VBA Editor
- Insert a Module from Insert Menu of VBA
- Copy the above code (for clearing the formats in a range using VBA) and Paste in the code window(VBA Editor)
- Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
- Press ‘F5′ to run it or Keep Pressing ‘F8′ to debug the code line by line.
Now you can observe that the formats in the range “A2 to D10” are cleared. You can apply any formats and background color, and try this macro. This will clear only the formats and the data, comments will be remained same.
Range.ClearFormats:Will clear only the formats of a range, remaining elements untouched.
Range.ClearContents: Will clear only the content/data of the range, formats will remain same.
Range.Clear: Will clear the data including cell formats.
Range.ClearComments: Will clear only the comments, formats and data will remain then same.
Hey! Join Our Community
Get Quick Responses & Experts' Answers in Minutes!
Get Notified - When Answered Your Question!