Be the first user to complete this post
|
Add to List |
VBA-Excel: Clear data from Excel Sheet(WorkSheet)
VBA-Excel: Clear data from Excel Sheet(WorkSheet)
Format: WorkBook.WorkSheet.Range.Clear
Examples:
mainworkBook.Sheets(3).UsedRange.Clear
Clear data from particular cell:
Dim mainworkBook As Workbook
Set mainworkBook = 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 particular column:
mainworkBook.Sheets("MyFirstMacro").Range("A:A").Clear
-Will clear the data from entire column “A”
Clear data from particular 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: Remember “.Clear” will clear the everything from the cell right from cell data to cell formatting, borders etc
If you just want to clear the content or data of the cells without effecting the format and border of the cell use “.ClearContents”
mainworkBook.Sheets("MyFirstMacro").Range("C6").ClearContents
Also Read:
- VBA Excel - Cells, Ranges and Offset : Range
- VBA-Excel: Add Worksheets For All The Given Dates Except Weekends and Copy The Common Template In Each Worksheet
- VBA-Excel: Delete Blank Rows from Excel Work Sheet
- Excel-VBA : Insert Multiple Images from a Folder to Excel Cells
- VBA-Excel: Add/Insert multiple objects from a folder in an Excel Document.