使用VBA清除Excel单元格格式,而不清除NumberFormat [英] Clear the Excel cells format using VBA without clearing the NumberFormat

查看:92
本文介绍了使用VBA清除Excel单元格格式,而不清除NumberFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不更改给定单元格的" NumberFormat "的情况下(使用VBA)清除Excel单元格格式和内容.

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

我尝试使用" .ClearContents "&" .ClearFormats ",但ClearFormats也删除了单元格的 NumberFormat .

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

请提出建议.

推荐答案

您可以执行以下操作:

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.

这篇关于使用VBA清除Excel单元格格式,而不清除NumberFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆