How to delete multiple columns in Excel VBA?

2020-08-02 01:58发布

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

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?

标签: excel vba
1条回答
三岁会撩人
2楼-- · 2020-08-02 02:39

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

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
查看更多
登录 后发表回答