I am really a freshman to study the VBA. I am confused about how to add an error message in a function subroutines.
Here is my problem, when I finished identify a function, how can I add an error message like this: "Please enter the value in an increasing order"?
e.g: If I type =triangular(3,2,1), where the number is in a decreasing order, I should get an error message.
Here is my code:
Public Function triangular(Minimum As Single, mostlikelyvalue As Single, maximum As Single) As Single
Dim uniform As Single
Dim d As Single
Randomize
Application.Volatile
d = (mostlikelyvalue - Minimum) / (maximum - Minimum)
uniform = Rnd
If uniform <= d Then
triangular = Minimum + (maximum - Minimum) * Sqr(d * uniform)
Else
triangular = Minimum + (maximum - Minimum) * (1 - Sqr((1 - d) * (1 - uniform)))
End If
End Function