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. +, – & ÷.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: