I am trying to learn VBA by developing a simple calculator application and am running into a problem when trying to deal with the possibility of the user attempting to divide by zero. Here is my code:
Sub Division_Click() Call Calculator user_input1 = Input_Box1.Value user_input2 = Input_Box2.Value If IsNumeric(Input_Box1.Value) And IsNumeric(Input_Box2.Value) Then Calc_Output = CDbl(Input_Box1.Value) / CDbl(Input_Box2.Value) If Input_Box1.Value <> 0 And Input_Box2.Value <> 0 Then Output_Box.Value = Calc_Output Else: MsgBox ("You Can't Divide by Zero...") Else: MsgBox ("Please Ensure All Entered Values Are Numeric") End If
When trying to run this code, I am told the final Else statement is without an If statement. However due to my indenting it should clearly relate to the first If?
If anyone could help out a confused beginner, that would be great! Thank you.