Good afternoon.
I'm new to VBA programming and I'm learning how to create user defined functions. I've created a user defined function (The function is called "Quadratic") that calculates the roots of a square function ax˛+bx+c=0 and recieves as inputs the numbers a, b and c, however, when I use the function in excel and I write in a cell "=QUADRATIC(" I would like to see these little hints that appears like "a;b;c" to know which are the parameters that I have to put in each argument of the function. I would like to know if someone could help me about this questions please? I attach the code here:
Public Function QUADRATIC(a As Variant, b As Variant, c As Variant) As Variant
Dim ANS(1) As Variant
Dim Discriminant As Variant
Discriminant = ((b ^ 2) - 4 * a * c)
If Discriminant >= 0 Then
ANS(0) = (-b + (b ^ 2 - 4 * a * c) ^ (1 / 2)) / (2 * a)
ANS(1) = (-b - (b ^ 2 - 4 * a * c) ^ (1 / 2)) / (2 * a)
QUADRATIC = ANS
End If
If Discriminant < 0 Then
ANS(0) = Application.WorksheetFunction.Round((-b / (2 * a)), 3) & "+" & Application.WorksheetFunction.Round(((Abs(Discriminant)) ^ (1 / 2)) / (2 * a), 3) & "i"
ANS(1) = Application.WorksheetFunction.Round((-b / (2 * a)), 3) & "-" & Application.WorksheetFunction.Round(((Abs(Discriminant)) ^ (1 / 2)) / (2 * a), 3) & "i"
QUADRATIC = ANS
End If
End Function
Thanks for your attention and help, have an amazing day.
Bookmarks