I'm trying to make a simple averaging function that does a bit of extra data processing.
The problem I'm facing is that I can currently work with a range input with my code (AvgFunc(rng as Range))
, however when selecting multiple inputs ([In a cell] =AvgFunc(A1, B8, C22))
it breaks.
So I decided instead of making a universal function code, I wrote a separate code to deal with the problem
Public Function AvgFunc_Selection(arg1 as Double, arg2 as Double, arg3 as Double, arg4 as Double, arg5 as Double)
However I'm obviously doing something wrong because I cannot get beyond that point.
Any suggestions on how to make a function that works with multiple inputs?
Here is the full code:
Public Function AvgFunc_Selection(arg1 As Double, arg2 As Double, arg3 As Double, arg4 As Double, arg5 As Double)
Dim temp1 As Double
Dim temp2 As Double
Dim Count As Integer
temp1 = arg1
If temp1 > 0 Then
temp2 = temp2 + temp1
Count = Count + 1
End If
temp1 = arg2
If temp1 > 0 Then
temp2 = temp2 + temp1
Count = Count + 1
End If
temp1 = arg3
If temp1 > 0 Then
temp2 = temp2 + temp1
Count = Count + 1
End If
temp1 = arg4
If temp1 > 0 Then
temp2 = temp2 + temp1
Count = Count + 1
End If
temp1 = arg5
If temp1 > 0 Then
temp2 = temp2 + temp1
Count = Count + 1
End If
AvgFunc_Selection = temp2 / Count
End Function