我基本上是在尝试为包含未知范围的单元格提供公式。但是我一直在出错。 “ inpt1”根据inpt1的计数而变化,因此我无法表述它。随着inpt1的更改,由于范围的变化,我也无法控制求和公式。让我说明一下;
Cells(inpt1 + 3, 4).Formula = "=SUM(" & Range(Cells(3, 9), Cells(inpt1 + 2, 9)) & ")"
我添加了一个示例图片供大家更好地理解。
Try to sum the prices of I3:I5 & write it as a formula in green area in the picture
答案 0 :(得分:0)
您需要向公式返回一个字符串。
当前:
Range(Cells(3, 9), Cells(inpt1 + 2, 9))
正在尝试将变体数组返回到公式字符串。变体数组不能转换为字符串。
您需要地址字符串。为此,我们在范围的末尾添加.Address
:
Range(Cells(3, 9), Cells(inpt1 + 2, 9)).Address
答案 1 :(得分:0)
您能尝试一下吗?
Cells(inpt1 + 3, 4).Formula = "=SUM(I9:I" & inpt1 + 2 & ")"
祝你好运