1

i Have 700 columns in a sheet. I want to delete more than 650 out of them. If I use range as A:W and more then I get 400 Error.

Is there any limit to no. of column deletion in VBA.

Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31

1 Answers1

0

Loop through them from rightmost column and delete them one by one.

Sub test()
Dim c As Long, r As Long
    Worksheets(1).Activate
    'populate 700 columns
    For c = 1 To 700
        Cells(1, c).Value = "col " & c
        For r = 2 To 10
            Cells(r, c).Value = "hej " & c & "/" & r
        Next
    Next
    'remove e.g. even columns
    For c = 700 To 1 Step -2
        Columns(c).Select
        Selection.Delete Shift:=xlToLeft
    Next
End Sub
Tim Stack
  • 3,209
  • 3
  • 18
  • 39
Jörgen R
  • 366
  • 1
  • 10