通过VBA删除多列

时间:2019-06-19 06:07:46

标签: vba

i工作表中有700列。我要删除其中的650多个。如果我将范围用作A:W,则得到400 Error

没有限制。 VBA中的列删除操作。

1 个答案:

答案 0 :(得分:0)

从最右边的列中浏览它们,然后将它们一一删除。

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