Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear 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 the 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 spreadsheet shift to replace the deleted cells.

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

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

like image 752
MackM Avatar asked Aug 07 '15 18:08

MackM


People also ask

How do I use single command to clear content and format in Excel?

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 the formatting, you can use . ClearFormats .

Is there an Excel shortcut for clear contents?

The first way to clear content in Excel is to use the Clear Contents shortcut. To do this, simply select the cells you want to clear, then press the Ctrl + Shift + Del keys on your keyboard. This shortcut will instantly clear the contents of the selected cells.

How do I clear formatting and text in a cell in Excel?

You can clear all of the formatting from selected cells by first selecting the cells from which you want to remove all of the formatting. Then click the “Home” tab in the Ribbon. Then click the “Clear” button in the “Editing” button group.


1 Answers

Use the .Clear method.

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

MSDN documentation here.

like image 78
MackM Avatar answered Sep 22 '22 21:09

MackM