在vba中简单的SumIf

时间:2015-10-22 20:42:46

标签: vba sumifs

我尝试使用提示范围在vba中执行sumifs功能。这就是我到目前为止所拥有的:

Sub SumIfPositiveSelectedRange()
    Dim ThisRng As Range
    Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
    ActiveCell.Formula = "=SUMIF((" & ThisRng.Address & "),">0")"
    End Sub

我得到一个Complile错误:预期:声明结束。我错过了什么?

1 个答案:

答案 0 :(得分:2)

根据我的评论。当希望引号保留在字符串中时,必须使用双引号,如下所示:

Sub SumSelectedRange()
Dim ThisRng As Range
Set ThisRng = Application.InputBox("Select a range", "Get Range", Type:=8)
ActiveCell.Formula = "=SUMif(" & ThisRng.Address & ","">0"")"
End Sub