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
How to delete multiple columns in Excel VBA?
提问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

