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

房东的猫 提交于 2019-12-03 10:50:35

问题


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?


回答1:


Use the .Clear method.

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

MSDN documentation here.



来源:https://stackoverflow.com/questions/31884818/clear-contents-and-formatting-of-an-excel-cell-with-a-single-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!