delete rows without loosing the formula in excel using vba

人盡茶涼 提交于 2019-12-24 14:46:41

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/31558274/delete-rows-without-loosing-the-formula-in-excel-using-vba

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