0

我正在尝试格式化大型报告并想使用宏。例如,我可能需要每隔一列插入一个新列,然后对其进行着色并插入一些数据。对于插入新列部分,而不是:

Sub Macro1()
'
' Macro1 Macro
'

'
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("C:C").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("E:E").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    .....repeated 1000 times  :-(
End Sub

我想要更多类似的东西:

' Do this for columns A - ZZ
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns(move over 2 columns).Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
'Run until Columns(":") > "ZZ:ZZ"
End Sub

我熟悉其他语言的 OOP,希望有人能对循环这些琐碎的任务有所了解!

4

1 回答 1

1
Dim rng As Range, x As Long

Set rng = ActiveSheet.Range("A1:J1")
For x = rng.Cells.Count To 1 Step -1
    rng(x).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Next x
于 2013-07-16T18:34:37.753 回答