I would like to create a custom Sum function using VB.
If would Sum two ranges numerator and denominator and then divide N/D.
It would only add values to the Num and Den if they were positive in both columns eg.
Num Den
5 10 Include
0 5 Don`t Include
10 2 Include
5 -5 Don`t include
So the Num = 15 and Den = 12 so output would be 15/12 = 1.25
So far I have ...
Function Create_aggregate(Numerator As Range, Demoninator As Range)
Dim SumN As Integer
Dim DumD As Integer
For Each i In Numerator
For Each j In Denominator
If i.Value > 0 Then SumN = SumN + i
If j.Value > 0 Then SumD = SumD + j
Else: SumN = SumN - i
Next i
Next j
Create_aggregate = SumN / SumD
End Function
This is effectively the sumif formula which works for one for each but not for two .. Thanks for suggestions
Bookmarks