For the following user defined function "averagefordates" i receive #Value Error. It worked 2 hours ago but i am not able to resolve it. Any help highly appreciated.
Function average values for certain specific dates
Public Function averagefordates(datecol As Range, valuecol As Range, date1 As Date, date2 As Date) As Double
Dim dx, vx, sumx As Double, countx As Long, i As Long
On Error GoTo errhdl
dx = datecol.Value
vx = valuecol.Value
If UBound(dx, 1) <> UBound(vx, 1) Then GoTo errhdl
For i = 1 To UBound(dx, 1)
If dx(i, 1) = "" Or IsEmpty(dx(i, 1)) Then
Else
If dx(i, 1) >= date1 And dx(i, 1) <= date2 Then
sumx = sumx + vx(i, 1)
countx = countx + 1
End If
End If
Next i
averagefordates = 0
If countx > 0 Then
averagefordates = sumx / countx
End If
normal_exit:
Exit Function
errhdl:
averagefordates = "error"
GoTo normal_exit
End Function
Bookmarks