0

目标:编写 VBA 子程序,它将设置一个不连续的范围,特别是 13 列 - 每隔一列 - 等于点击事件时 13 列宽和 132 行长的连续数据范围。

我有两个财务报表,我希望能够并排比较。单击活动的 x 按钮,在财务报表 1 的列之间插入列,然后从财务报表 2 中提取列(包含在另一张表中)并将它们显示在财务报表 1 中相应列的旁边。

仅使用 VBA 代码。采取什么是

总计|一月|二月|三月....

总计|总计|一月|一月|二月|二月|三月|三月.....

我开发的当前代码运行速度非常慢,并且由于某种原因在每列之间插入了一个“June”列。

帮助!

Sub BudgetBudgetCheck_Click()

If BudgetActual.Value = "True" And BudgetBudgetCheck.Value = "True" Then
    For colx = 6 To 36 Step 2
    Columns(colx).Insert shift = xlRight
    Next
    End Sub

Private Sub BudgetActual_Click()
For i = 4 To 28 Step 2
For j = 2 To 14
Columns(i).Value = Worksheets("P&L - Monthly Budget").Columns(j).Value
Next
Next
End If
End Sub
4

1 回答 1

0
Dim rngOne as range, rngTwo as range, x as long, col_offset

Set rngOne = worksheets("statement1").Range("A1").resize(132,13)
Set rngTwo = worksheets("statement2").Range("A1").resize(132,13)

with worksheets("summary")
    .usedrange.clearcontents
    for x=1 to 13
        col_offset = (x-1)*2      
        rngOne.columns(x).copy .cells(1,col_offset+1)
        rngTwo.columns(x).copy .cells(1,col_offset+2)
    next x
end with
于 2013-02-08T01:37:18.180 回答