Returning #value when for string after an Excel calculation

69 views Asked by At

This user defined function calculates some value; according to that I need to return a string in the calling cell.

The MsgBox test in the function works, but in the cell I am getting only a #value! error.

Why?

Function WoodClassify(Length As Double, Girth As Double, Description As String) As Double
    Dim cubicMeter As Double
    Dim Classification As String


If Length > 250 Then
    MsgBox ("TG B(I)")
    Classification = "TG B(I)"
ElseIf Length > 100 Then
    Classification = "XXXXXXX"
Else
    Classification = "WWWWWWWW"
End If

WoodClassify = Classification

End Function
1

There are 1 answers

0
Lefty On BEST ANSWER

Function WoodClassify(...) as Double

Classification is a string, and you've set the function to return a double. It can't implicitly convert a string to a double so it gives a value error.

If you want the function to return a string that should read: Function WoodClassify(...) as String