I've just read that you can create your functions and access them from Excel formulas so I created the below which I'm going to find useful:
It basically replaces:
=SUMIF(D8:H8,">0"
/COUNTIF(D8:H8,">0"
with:
=ClnAvg(D8:H8)
with the benefit of you won't get a #DIV/0! if there is nothing to average.
[tt]
Function ClnAvg(Range)
Dim mycell As Object
counter = 0
thetotal = 0
For Each mycell In Range
If IsNumeric(mycell.Value) = True Then
If mycell.Value <> "" Then
thetotal = thetotal + mycell.Value
counter = counter + 1
End If
End If
Next mycell
If thetotal = 0 Then
ClnAvg = ""
Else
ClnAvg = thetotal / counter
End If
End Function
[/tt]
It can be altered to return 0 if there is nothing to average, or eliminate 0s from the input.
It basically replaces:
=SUMIF(D8:H8,">0"
with:
=ClnAvg(D8:H8)
with the benefit of you won't get a #DIV/0! if there is nothing to average.
[tt]
Function ClnAvg(Range)
Dim mycell As Object
counter = 0
thetotal = 0
For Each mycell In Range
If IsNumeric(mycell.Value) = True Then
If mycell.Value <> "" Then
thetotal = thetotal + mycell.Value
counter = counter + 1
End If
End If
Next mycell
If thetotal = 0 Then
ClnAvg = ""
Else
ClnAvg = thetotal / counter
End If
End Function
[/tt]
It can be altered to return 0 if there is nothing to average, or eliminate 0s from the input.