##指定列求和

需求:

求和:列为“销售金额”的数值

[VBA]指定列求和-LMLPHP

Sub 求和()
Dim i As Integer, j As Integer
For i = 3 To 56
For j = 15 To 81 Step 2
Cells(i, 13) = Cells(i, 13) + Cells(i, j)
Next j
Next i

End Sub

中间有一段无法调试的代码,

Sub 求和()
Dim i As Integer, j As Integer
For i = 3 To range("a65536").end(xlup).row step 1
For j = 15 To range("a1").end(xltoright).column Step 2
Cells(i, 13) = Cells(i, 13) + Cells(i, j)
Next j
Next i

End Sub

标黄的代码没有报错,但是无法运行处结果,改成上面的代码中的56 和81 之后,代码就可正常运行。

结果:

[VBA]指定列求和-LMLPHP

05-11 16:07