On UrbanPro

View My Profile       Proud to be a Teacher       Write a Review  

Monday, June 27, 2016

VBA Code to clear Content in Entire Sheet

VBA Code to clear an entire sheet in Excel uses the clear contents method, however all that does is clear the data from the cells and not the formatting. To truly clear all the cells and start with a blank canvas you need to use the delete method. Finally we looked at the structure of the VBA script and how to amend it to change your VBA from deleting the contents of cells to deleting the entire worksheet from your Excel workbook.

VBA Code Syntex 

 Sheets(“INSERT WORKSHEET NAME HERE”).Cells.ClearContents  

VBA Code/Macro to Clear Content

 Sub ClearSheet()  
 Sheets(“Sheet1”).Cells.ClearContents  
 End Sub  
OR
 Sub ClearSheet()  
 Sheets(“Sheet1”).Cells.Delete  
 End Sub  
OR
 Sub ClearSheet()  
 Sheets(“Sheet1”).Delete  
 End Sub