0

我有这段代码用于将“sum”公式粘贴在同一行但在不同的列中(实际上,这不完全是公式,“sum”仅用于解释)

for i = 1 to 100
Cells(2, (1 + 5 * (i - 1))).Formula = "=sum($A$1:$E$1)"
Next

但是,我需要这个公式来改变每次迭代,就像它粘贴的单元格一样。然后,Cell "A1"( for i = 1) 必须在更改为when"F1"的同时更改为。我怎样才能使这个循环通过列?"E1""J1"i = 2

提前致谢!

路易斯

4

2 回答 2

1
For i = 1 to 100
    Cells(2, 5 + ((i - 1) * 5)).FormulaR1C1 = "=SUM(R[-1]C[-4]:R[-1]C[0])"
Next
于 2013-05-07T19:48:37.437 回答
0

试试下面的代码:

 Dim colChar As String, colChar5 As String
    For i = 1 To 100 Step 5
        colChar = Split(Cells(, i).Address, "$")(1)
        colChar5 = Split(Cells(, i + 4).Address, "$")(1)
        Cells(2, i).Formula = "=sum(" & colChar & "1:" & colChar5 & "1)"
    Next
于 2013-05-08T01:17:13.187 回答