I have been asked at work to produce a formula which will do a sumif on a range in a single row where the criteria are in adjacent cells.
For example 20,1, 10,1,15,2
The result would sumif if the cell to the right is 1 - giving an answer of 30 in the above array.
I am struggling to produce a formula that can do this so I have gone to a custom function. What I have is below (which doesn't work)
Public Function MattsSumIF(Criteria As Double, NRange as range)
Dim Cell As Range
Total = 0
i = 1
For Each Cell In NRange
If ActiveCell.Offset(0, i).Value = Criteria Then
Total = ActiveCell.Value + Total
i = i + 1
MattsSumIF = Total