I have a FormulaArray in excel which is
{=MAX(IF($DB$2:$DI$2<F10,$DB$2:$DI$2))}
and it worked perfectly. "F10" is equal 55, "then $DB$2:$DI$2" is a range of values between 41-102. Then i created a vba function and apply it in excel as a formula
=ClosestLessThan(F10,$DB$2:$DI$2)
but the result is #VALUE!", i cant figure out the right way. Here is what i have tried.
Function ClosestLessThan(searchNumber As Double, rangeOfValues As Range) As Double
Dim rng As Range
If rangeOfValues < searchNumber Then
Set rng = rangeOfValues
End If
ClosestLessThan = Application.WorksheetFunction.Max(rng)
End Function