4

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?

4
  • Range("A:C,E:E,H:S,U:AK,AM:AM,AO:AU,BC:BI,BK:BV").Delete Commented Oct 1, 2015 at 8:41
  • 1
    I get a msg Run time error 1004 Delete method of range class failed Commented Oct 1, 2015 at 8:55
  • Then something else is a problem - the code above works for me. Are there merged cells in your spreadsheet that might be blocking the deletion? Commented Oct 1, 2015 at 9:00
  • No merge cells. I use the code on a table which is shown after double clicking on a pivot table (show details). I have many columns then which I do not need. Commented Oct 1, 2015 at 9:02

1 Answer 1

9

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
Sign up to request clarification or add additional context in comments.

2 Comments

I get a msg Run time error 1004 Delete method of range class failed
I just executed same code here and it is working fine. Can you please check with one or two ranges and see if any errors coming?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.