Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write this formula in VBA?

I have this formula to solve.
enter image description here

And here is my code that outputs an error in the formula.

Private Sub CommandButton6_Click()
Dim Z As String
Dim X As Double, Y As Double
Z = InputBox("Input number X!", "Inputing number X"): X = Val(Z)
Y = Sqr(2 * ((X - 2) ^ 2) * ((8 - X) - 1)^1/3
MsgBox ("Y =" + Str(Y))
End Sub

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Taking into account when we get negative result under the root

Y = (2 * ((X - 2) ^ 2) * (8 - X) - 1)
If Y >= 0 Then
    Y = Y ^ (1 / 3)
Else
    Y = -(Abs(Y) ^ (1 / 3))
End If
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading