Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I clear cell contents without changing styling?

Tags:

Is there a way to clear the contents of multiple cells, but without changing the background/font properties of the cells?

I am currently using Range("X").Cells.Clear but its removing my background color and I would prefer not to have to "repaint" it on each clear.

like image 325
mezamorphic Avatar asked Jun 21 '12 11:06

mezamorphic


People also ask

How do I clear contents in Excel but not formatting?

To clear all contents, formats, and comments that are contained in the selected cells, click Clear All. To clear only the formats that are applied to the selected cells, click Clear Formats. To clear only the contents in the selected cells, leaving any formats and comments in place, click Clear Contents.

Does clear contents remove formatting?

This will erase all cell formatting (including conditional formatting, number formats, fonts, colors, borders, etc.) but keep the cell contents.

How do I clear specific content in Excel?

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. If you want to clear the formatting of cells, but keep the contents, you can use the Clear Formats shortcut.

How do I remove formatting without removing contents?

You can also remove formatting from the entire worksheet without removing any contents. ➤ First, select all the cells by clicking on the arrow sign from the intersect point of the row and column number. ➤ After that, go to Home > Editing > clear and select Clear Formats.


2 Answers

You should use the ClearContents method if you want to clear the content but preserve the formatting.

Worksheets("Sheet1").Range("A1:G37").ClearContents 
like image 137
stuartd Avatar answered Sep 27 '22 19:09

stuartd


you can use ClearContents. ex,

Range("X").Cells.ClearContents 
like image 45
seegoon Avatar answered Sep 27 '22 19:09

seegoon