Clear the Excel cells format using VBA without clearing the NumberFormat

帅比萌擦擦* 提交于 2020-06-27 17:11:59

问题


Is it possible to clear Excel cell format and content (using VBA) without altering the “NumberFormat” of the given cell.

I’ve tried with “.ClearContents” & “.ClearFormats”, but ClearFormats removed the NumberFormat of the cells too.

Please suggest.


回答1:


You could do something like this:

Dim t
t = Range("A1").NumberFormat
Range("A1").ClearFormats
Range("A1").NumberFormat = t

It will save the number format then reapply it after clearing everything else.



来源:https://stackoverflow.com/questions/35923490/clear-the-excel-cells-format-using-vba-without-clearing-the-numberformat

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