问题描述:

I'm using VBA to sum the values of the cells within my SumRange given that they are positive numbers. The code works, however, it is not returning an answer with decimal places when it should have them.

RecebimentosValor = WorksheetFunction.SumIf(SumRange, ">0")

网友答案:

Be sure to use Double:

Sub ytrewq()
    Dim SumRange As Range, RecebimentosValor As Double
    Set SumRange = Range("A1:A10")
    RecebimentosValor = WorksheetFunction.SumIf(SumRange, ">0")
    MsgBox RecebimentosValor
End Sub

网友答案:

I see no problems with

Sub M_snb()
 y = [sum((A1:A12>0)*(A1:A12))]
 y = Application.SumIf(Range("A1:A12"), ">0")
End Sub
网友答案:

Not always. It depends on your input. If your input in decimal format then output will be produce in Decimal form. Simple mathematics rule.

相关阅读:
Top