Good morning, everyone.
Can someone please help me with my UDF below. If I remove the code comparing to MY_CELL, it will sum up everything in theRange, but no matter how I do it, I can't get it to sum up only if the value in Column D of that row is equal to MY_CELL. It goes to FuncFail and gives me MY_CELL as the result.
Any other suggestions would be great as well. I do know that using Application.Caller is supposed to not be very efficient. Thanks in advance!
Can someone please help me with my UDF below. If I remove the code comparing to MY_CELL, it will sum up everything in theRange, but no matter how I do it, I can't get it to sum up only if the value in Column D of that row is equal to MY_CELL. It goes to FuncFail and gives me MY_CELL as the result.
Code:
Function FG(theRange As Range)
Dim vArr As Variant
Dim v As Variant
Dim r As Double
Dim MY_CELL
Dim d As Double
On Error GoTo FuncFail
r = 0
vArr = theRange.Value2
MY_CELL = Cells(Application.Caller.Row, 4) & Cells(Application.Caller.Row, 5) & Cells(Application.Caller.Row, 6)
For Each v In vArr
d = CDbl(v)
If Application.WorksheetFunction.IsNumber(v) Then
If Cells(v.Row, 4) = MY_CELL The
r = r + d
End If
End If
Next v
FG = r
Exit Function
FuncFail:
FG = MY_CELL
End Function
Any other suggestions would be great as well. I do know that using Application.Caller is supposed to not be very efficient. Thanks in advance!