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


uses of vlookup in excelinsert text box excelfinding doubles in exceltraining schedule template excelexcel vba while loopsales trend analysis excel templatehow to organize in alphabetical order in excelexcel vba concatenate cellsarrays in excel vbatutorial vlookuphighlight duplicates excel 2010excel worksheet rangedml sqlturn on macros in excelvba xldo while loop vba excelvba excel call functionvba sql statementwhat is hlookuphow to delete a row in excel using vbarows in ms excelundo macro excelproject timetable template excelunhide column a in excelremove duplicate values in excelexample of vba codehow to insert combobox in excelexcel cost estimate templateexcel vba concatenateproject calendar template excelfso copyfilehow unprotect excel sheetexcel if isna vlookupexcel vba scriptsproject tracker template excelvb function syntaxend loop vbaworking with macros in excel 2007array functions vbadelete macro buttonexecutive project dashboard templateredim preserve array vbaexcel vba create text filenot equal vbadashboard templates excelhow to calculate the difference between two dates in excelrecording excel macroshow to use countif function in excel 2007vba pivot table rangeexcel formulas made easyexcel vlookup rangehow to create database in excel sheetvisual basic hyperlinkcells.find excelms excel developer tabwhat is the countif function in excelhlookup vs vlookupexcel checkbox columnvb6 sql server connection stringvba exampivottables in excelthissheet vbaexcel vba refresh pivot tableexcel export to txtvlookup function in excel 2013vb6 backcolorexcel vba instr functionautofilter excel 2013learning vlookup in excelvlookup excel step by stepconcatenate formula excelvba unload userformexcel vba worksheet copy