vba code to clear the sheet data code example

Example 1: excel vba clear contents and formatting of cell with a single command

'To clear a worksheet range from VBA, use one of
'the 'Clear' methtods:

[A1].Clear           '<-- clears everything in the Range cells
[A1].ClearFormats    '<-- clears only the formats
[A1].ClearContents   '<-- clears values but not formats
[A1].ClearHyperlinks '<-- clears hyperlinks only
[A1].ClearNotes      '<-- clears notes only

Example 2: excel vba quickest way to clear sheet contents

'VBA methods to quickly clear a sheet.

'Remove values 
'but not formatting:
Sheet1.UsedRange.ClearContents

'Remove formatting
'but not values:
Sheet1.UsedRange.ClearFormats

'Remove everything:
Sheet1.UsedRange.Clear

'Remove everything potentially faster:
Sheet1.UsedRange.Delete

'Remove everything, fastest:
With Application
	.Calculation = xlManual
    .ScreenUpdating = False
    
    Sheet1.UsedRange.Delete
    
    .ScreenUpdating = True
    .Calculation = xlAutomatic
End With

Tags:

Vb Example