如何在Excel VBA中删除多个列? [英] How to delete multiple columns in Excel VBA?

查看:307
本文介绍了如何在Excel VBA中删除多个列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Excel VBA中删除多个列?我试过了:

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?

推荐答案

您可以对Range使用delete方法删除列.

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

就您而言,

Sub DelColumns()

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

End Sub

这篇关于如何在Excel VBA中删除多个列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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