Попробуйте вместо этого использовать Application.SumIf ...
Function HoursFlown() As Double
'writes formula for cells d10:d14 to calculate hours flown
'checks across all worksheets (each day of month) confirms pilot
'and a flight exists and sums "flight hours totals" for toatal hours in month to date.
'!!!At present this is not a function so does not return a result and takes no arguments.
Application.Volatile
Dim WS_Count As Integer
Dim I As Integer
Dim total As Double
' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
total = 0
For I = 2 To WS_Count
total = total + Application.SumIf(ActiveWorkbook.Worksheets(I).Range("L3:L4"), Range("c10").Value, ActiveWorkbook.Worksheets(I).Range("M3:M4"))
Next I
HoursFlown = total
End Function
EDIT
Для IntelliSense вы можете обратиться к члену SumIf объекта WorksheetFunction ( ie. WorksheetFunction.SumIf (...)). Однако, в этом случае, если он возвращает ошибку, вы получите ошибку прерывания, которую вам нужно будет обработать.
С Application.SumIf, однако, если возвращается ошибка, вы ' Вы получите неразрывную ошибку , для которой вы можете проверить с помощью функции IsError ...
Dim total as Variant 'declared as Variant in case SumIf returns an error
total = Application.SumIf(.....)
If Not IsError(total) Then
'do something
Else
'do something else
End If
Надеюсь, это поможет!