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.