VBA ClearFormats in Excel Explained with Examples

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.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA ClearFormats Method Excel Range Object

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.

Range(“YourRange”).ClearFormats

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:

  1. Open an Excel Workbook from your start menu or type Excel in your run command
  2. Enter some data in any cells in range “A10 to D10” to test this macro. Also format some cell to test this macro.
  3. 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
  4. Insert a Module from Insert Menu of VBA
  5. Copy the above code (for clearing the formats in a range using VBA) and Paste in the code window(VBA Editor)
  6. Save the file as Macro Enabled Workbook (i.e; .xlsm file format)
  7. 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.

LIMITED TIME OFFER

Leave A Comment


Related pages


vba sql recordsetvbscript write text filelistbox selectionhow to make drop down list in excel 2007how to enable developer tab in excel 2007excel function trimformulas in excel 2007 with examplesproject management chart excelshortcut key for pivot table in excel 2010application.goto vbavba if iserrorchange the width of a column in excel 2010unprotect excel workbook with passwordwhere is the developer tab in excel 2013using the macro recorder record a macroexcel 2010 unhide allvba tutorial pdfexcel macro open foldercomment excel vbanested if in excel 2010concatenate excel formulaproject planning freewarevbscript message boxexcel vba combo boxcolor cells in excelsql query from excelvba functions excelword vba message boxclustered column chart in excelvariant excel vbatimeline excel templatedef of syntaxvba excel saveasascending and descending order worksheetssql server macrovba excel color celltick in microsoft excelexcel merge cells with dataexcel macro concatenate stringexcel 2010 data validationproject status template exceliserror excel formulaexcel tutorial macrosselect last row vbahow to enable macro excel 2007excel trim formulavbscript code examplesdelete row excelhow to unprotect sheet in excel 2010 without passworddelete duplicate datavba unprotect workbookexcel formula from another sheetsum if sqlexcel construction schedule templatewriting vba code in excelexcel 2010 macro recorderactivex control examplevba excel copy sheetexcel vba applicationsql interview questions for fresherhow to use the sumif function in microsoft excel 2010concatenate function in excelautofit in excel vbavba find duplicatesvba print functionvba listbox selected itemvisual basic excel 2007 tutorial pdfword and excel test for interviewvba copy worksheetexcel macro rowsexamples of dashboards in excelupdate vba accessreverse vlookupshortcut key to delete a row in excelrun vba in excel