This is my code
Code
Private Sub CommandButton1_Click()
Dim a, b, c, det, root1, root2 As Single
a = Cells(2, 2)
b = Cells(3, 2)
c = Cells(4, 2)
det = (b ^ 2) - (4 * a * c)
If det > 0 Then
root1 = (-b + Sqr(det)) / (2 * a)
root2 = (-b - Sqr(det)) / (2 * a)
Cells(5, 2) = Round(root1, 2)
Cells(6, 2) = Round(root2, 2)
ElseIf det = 0 Then
root1 = (-b) / (2 * a)
Cells(5, 2) = root1
Cells(6, 2) = "Only one answer"
ElseIf det < 0 Then
root1 = (-b + (Sqr(det * -1)) / (2 * a)) + "i"
root2 = (-b - (Sqr(det * -1)) / (2 * a)) + "i"
Cells(5, 2) = Round(root1, 2)
Cells(6, 2) = Round(root2, 2)
End If
End Sub
Display More
Everything above "ElseIf det < 0 Then" works but I cant get the imaginary number part to work