VBA Clear Range in Excel explained with Examples

VBA Clear Range in Excel will Clear a specific range or entire worksheet using Clear method of Range Object. ‘Rang.Clear’ method will clear the range including the formats like border, font styles, background cell and set to default.

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 Clear Method Excel Range Object

Excel VBA to Clear a Range – Syntax

Here is the syntax to clear a range. You can clear the data in any range including formats using VBA ‘Range.Clear’ method.

Range(“YourRange”).Clear

Excel VBA to Clear a Range – Examples

The below macro will show you how to clear a range using VBA. In this example, we are clearing range “A2 to D10” using VBA.

Sub VBA_Clear_Range()
Range("A2:D10").Clear
End Sub

Excel VBA to Clear 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.
  3. Press Alt+F11 to Open VBA Editor or you can goto 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 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 data in range “A2 to D10” is clear. You can apply any formats and background color, and try this macro. This will clear everything and set to the default.

If you want to clear only the data you can use Range.ClearContents method, to clear the comments in a range you use the Range.ClearComments method.

Range.Clear: Will clear everything including cell formats.
Range.ClearContents: Will clear only the content/data of the range, formats will remain same.
Range.ClearComments: Will clear only the comments, formats and data will remain same.

LIMITED TIME OFFER

Leave A Comment


Related pages


resource planning spreadsheet templatecells excel vbaexcel vba unhide sheetms excel macro tutorialvba open applicationexcel chart wizard 2010vbokonly exampleexcel charts sampleshide columns excelremove duplicate excel 2003formula vba excelpivoting tables in excelhow to delete unwanted cells in excelwritten test questions and answers for freshershow to get data from another worksheet in excelmicrosoft word macros examplesexcel programming tutorialshow do you create a macro in excelvba excel function returnexcel cells vbaexcel 2007 vba macro programming pdfaddress vbaexcel vba distinct valueshow to unhide a column in excel 2007excel vba write to text filehow to make radio buttons in excelmerge multiple excel worksheets into oneiserror excel formulaif statement in macro excelvb source code examplesopen file in excel vbaexcel vba save workbookvba basic tutorialhow to insert a checkbox in excelexcel 2010 advanced filterexcel xml formatvbinformation vbaexcel 2007 pivot table calculated fieldvba application.statusbarclear array vbacreate array in vbatutorial advanced excelvlookup hlookup pivot table tutorialvba sql statementworkbook definition exceldml and ddl queriesremove duplicate row in excelwriting vba functionsunmerge all cellsunhide all excel sheetscool excel spreadsheetssql sort tableexcel dashboard examples freeexcel vba countunhiding columns in excelhow to delete odd rows in excelexcel vba programming booksexcel 2010 stacked bar chartexcel 2007 vba tutorialmicrosoft vba excelhow to apply filters in exceldml dllhow to insert developer tab in excel 2010embedded chart excelvba case selectvba loop examplesvba code to save excel fileexcel linked cellsms excel lookupdelete selection vbasql interview questions and answers with examplesxls macrovba programming languagecreateobject vbahow to dedupe in exceladd developer tab to ribbon microsoft word