Clear the contents and formatting of an Excel cell with a single command

If you want to clear the contents of a cell or range in Microsoft Excel, you can use .ClearContents . If you also want to clear formatting, you can use .ClearFormats .

 Sheets("Test").Range("A1:C3").ClearContents Sheets("Test").Range("A1:C3").ClearFormats 

If you want to do both, you can use .Delete , but then the other cells in the table move to replace the deleted cells.

 Sheets("Test").Range("A1:C3").Delete 

How can you remove the contents and formatting of a cell or range in VBA with a single command without affecting the rest of the worksheet?

+8
vba excel-vba excel-2013
source share
1 answer

Use the .Clear method.

 Sheets("Test").Range("A1:C3").Clear 

MSDN documentation is here.

+21
source share

All Articles