我正在尝试执行一个简单的求和函数,它允许我事先定义范围,但我得到一个#NAME?错误。
Sub SumSelectedRange()
Dim ThisRng As Range
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
ActiveCell.Formula = "=SUM(ThisRng)"
End Sub
怎么了?
答案 0 :(得分:0)
使用范围或任何其他vba引用时,它必须在引号旁边。
像这样:
Sub SumSelectedRange()
Dim ThisRng As Range
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
ActiveCell.Formula = "=SUM(" & ThisRng.Address & ")"
End Sub