I’ve got a very simple VBA function that takes two range arguments and returns a double using the values of the two ranges. I’m using this in the formula bar of a single cell, but I’m wanting to return a string error should something not be quite right. Is there a way I can show this without it showing #VALUE in the cell?
Public Function CPP(aPreviousPercentage As Range, aCurrentPercentage As Range) As Double
If (aPreviousPercentage.Value > 0.2) Then
CPP = "Invalid Starting Value"
Exit Function
End If
CPP = aCurrentPercentage.Value - aPreviousPercentage.Value
End Function
Probably the best way to do this is change the return type to variant instead of double. That way if you’d like you can set it to a string instead of a numeric value.