VBA-Excel: Clear data from Excel Sheet(WorkSheet)

VBA-Excel: Clear data from Excel Sheet(WorkSheet)

For­mat: WorkBook.WorkSheet.Range.Clear         

Exam­ples:

mainworkBook.Sheets(3).UsedRange.Clear

Clear data from par­tic­u­lar cell:

Dim main­work­Book As Workbook

Set main­work­Book = ActiveWorkbook

mainworkBook.Sheets(“MyFirstMacro”).Range(“A2”).Clear

–Will clear the data from Cell “A2

Clear data from more than one cells:

mainworkBook.Sheets(“MyFirstMacro”).Range(“A1,C3”).Clear

–Will clear the data from Cell “A1” and “C3

Clear data from range of cells:

mainworkBook.Sheets(“MyFirstMacro”).Range(“A1:C4”).Clear

–Will clear the data from Range of Cells “A1” to “C4

Clear data from par­tic­u­lar column:

mainworkBook.Sheets(“MyFirstMacro”).Range(“A:A”).Clear

–Will clear the data from entire col­umn “A”

Clear data from par­tic­u­lar row:

mainworkBook.Sheets(“MyFirstMacro”).Range(“2:2″).Clear

–Will clear the data from entire Row 2.

Clear all the Used range of data:

mainworkBook.Sheets(3).UsedRange.Clear

Clear all data from more than columns

mainworkBook.Sheets(“MyFirstMacro”).Range(“A:F”).Clear

–Clear data for Columns from A to F

Clear all data from more than rows

mainworkBook.Sheets(“MyFirstMacro”).Range(“2:5″).Clear

 

Note: Remem­ber “.Clear” will clear the every­thing from the cell right from cell data to cell for­mat­ting, bor­ders etc

If you just want to clear the con­tent or data of the cells with­out effect­ing the for­mat and bor­der of the cell use “.ClearCon­tents

mainworkBook.Sheets(“MyFirstMacro”).Range(“C6”).ClearContents

Also read about:

Delete Blank Rows From Excel

Used Range

Cells Ranges and Offset

Happy Macro­ing :)

Sumit Jain

One thought on “VBA-Excel: Clear data from Excel Sheet(WorkSheet)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>