vba 如何删除Excel VBA中的多列?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32883041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:00:06  来源:igfitidea点击:

How to delete multiple columns in Excel VBA?

excelvba

提问by Przemyslaw Remin

How to delete multiple columns in Excel VBA? I tried:

如何删除Excel VBA中的多列?我试过:

Sub DelColumns()
  Dim col As Range

  For Each col In Range("A:C,E:E,H:S,U:AK,AM:AM,AO:AU,BC:BI,BK:BV").Columns
    col.EntireColumn.Delete
  Next col

End Sub

Update.I try to do it on a table which is a show-detail table of pivot table. Is it possible to delete table columns without converting the table to a range first?

更新。我尝试在一个表格上进行,该表格是数据透视表的显示详细信息表。是否可以删除表列而不先将表转换为范围?

回答by Shalvin Abraham

You can use the delete method against Range to delete columns.

您可以对 Range 使用 delete 方法来删​​除列。

In your case,

在你的情况下,

Sub DelColumns()

  Range("A:C,E:E,H:S,U:AK,AM:AM,AO:AU,BC:BI,BK:BV").Delete

End Sub