对两行A和B进行求和,得到列c但得到错误: - 对象变量或未设置块变量

时间:2018-04-22 17:53:24

标签: excel excel-vba vba

'class module:- clscustomer
Public z As Integer
Public rng As Range
Public c As Range

Public Sub sum(x As Integer, y As Integer)

z = x + y
'error here
c.Offset(0, 2).Value = z \\error hereva

End Sub

1 个答案:

答案 0 :(得分:0)

即使你设置了c,你也只能获得第一行的总和,你必须把你的代码放在一个循环中;你可以尝试在执行你想要完成的动作时录制宏;或者使用更基本的代码...

With ActiveSheet
    .Range("C2").Formula = "=SUM(A1,B1)"
    .Range("C2:C20").FillDown
End With