Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete multiple columns in Excel VBA?

Tags:

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?

like image 945
Przemyslaw Remin Avatar asked Oct 17 '25 16:10

Przemyslaw Remin


1 Answers

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
like image 140
Shalvin Abraham Avatar answered Oct 19 '25 12:10

Shalvin Abraham