开发者

How to delete the odd columns in an Excel file with VBA (or without)

开发者 https://www.devze.com 2023-02-14 20:08 出处:网络
Ok, i have this dataset where I need to delete startin from column for every other column. So i tried to do this with VBA since the dataset is quite large. I tried this but it will not work:

Ok, i have this dataset where I need to delete startin from column for every other column. So i tried to do this with VBA since the dataset is quite large. I tried this but it will not work:

Sub Macro2()
'
' Macro2 Macro
'

'
    For clNumber = 4 To 500

    clNumber.Select                      //doesn't work
    Selection.Delete Shift:=xlToLeft
    Next

End Sub

Any ideas on how to select the 开发者_Python百科column of which the number is clNumber and delete that?


Change clNumber to Columns(clNumber), as clNumber is just a number, but not an object.

Actually, it is better just to use

For clNumber = 4 To 500
  Columns(clNumber).Delete Shift:=xlToLeft
Next

as Select is unnecessary.


try

For clNumber = 4 To 500

Columns(clNumber).Select               
Selection.Delete Shift:=xlToLeft
Next


You want

Columns(clNumber).Select
0

精彩评论

暂无评论...
验证码 换一张
取 消