## Simple Calculator With Buttons

**An Extension Of The ‘Simple Calculator’ Project Including Buttons**

1. Right Click ‘VBAProject (ProjectName) > ‘Insert’ > ‘UserForm’

2. Click on the ‘CommandBox’ within the Toolbox.

3. Draw a box on the UserForm, to rename the box to e.g. +, -, ÷ , ×. Click the box you just drawn twice.

4. Double Click on the button you just made.

5. You should see something similar to below:

Private Sub CommandButton1_Click()

End Sub

6. Insert your ‘Simple Calculator’ code, it should now show the following:

Private Sub CommandButton1_Click()

Dim X_Value As Double

Dim Y_Value As Double

X_Value = InputBox(“Please enter a number”)

Y_Value = InputBox(“Please enter a number”)

Sum = X_Value * Y_Value

MsgBox “Answer to: ” & X_Value & ” * ” & Y_Value & ” = ” & Sum

End Sub

7. Click ‘Debug’ > ‘Compile VBAProject’ > ‘Run’

You can expand on this by including more buttons which can link to more codes e.g. +, – & ÷.