删除行,而不会使用vba在excel中丢失公式 [英] delete rows without loosing the formula in excel using vba

查看:170
本文介绍了删除行,而不会使用vba在excel中丢失公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个excel表,其中有一个表有一个下拉和一个正常的excel单元格。我尝试清除表的内容,我已经通过

  range(X)完成了ClearContents 

但问题是它要清除内容,但我可以看到表的边框



当我使用

  Range(X )。选择
Application.DisplayAlerts = False
Selection.Delete
Application.DisplayAlerts = True
范围(X)。选择
Selection.ClearContents

它删除表(内容和边框),但我可以看到下拉列表中的公式缺少ie



感谢提前!

解决方案

您可以使用 ClearFormats()方法,这将删除表边框。



另外,为了清除内容,你做不必先选择范围。利用 语句

  With Range(X)
.ClearContents
.ClearFormats
结束

上述应该达到你以后的目标。


I have an excel sheet in which there is one table with a drop down and one normal excel cell. I try to clear the contents of the table and I have done it through

range("X").ClearContents

but the problem with it is it is going to clearing the content but I'm able to see the table borders with it.

When I have used

Range("X").Select
Application.DisplayAlerts = False
Selection.Delete
Application.DisplayAlerts = True
Range("X").Select
Selection.ClearContents

It deletes the table (both content and borders) but it I can see the formula in the drop down is missing ie the drop down cell has become normal cell.

Thanks in Advance!

解决方案

You can use the ClearFormats() method, this will remove the table border.

Also, to clear contents, you do not have to first select the range. Take an advantage of the With statement

With Range("X")
    .ClearContents
    .ClearFormats
End With

The above should achieve what you're after.

这篇关于删除行,而不会使用vba在excel中丢失公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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