i have UDF for sum (A2-A1)+(A3-A2)+(A4-A3) + ... So on
when i am select =adc(A1:A5) result is true
but while 1 am select adc(A1:A11) result not correct
A1:A11 is empty
i has to use if for prevent calculation but not sukses
help me every body
Function adc(r As Range)
Dim x, i&, s&: x = r.Value
On Error Resume Next
For i = 1 To UBound(x, 1)
If (x(i, 1)) > 0 Or x(i, 1) <> Empty Then
If s = 0 Then
s = Val(x(i + 1, 1)) - Val(x(i, 1))
Else
s = s + Val(x(i + 1, 1)) - Val(x(i, 1))
End If
End If
Next i
adc = s
End Function
res.png
IN this picture result 40 is true but result -10 not true
Bookmarks