Simple Calculator

Building A Simple Calculator Program

1. Create New Module: right click on ‘VBAProject (ProjectName)’ > ‘Insert’ > ‘Module’

2. In the Code Window copy the following code:

Sub MyFirst_Calculator()

Dim X_Value As Double
Dim Y_Value As Double

X_Value = InputBox(“Please enter a number”)
Y_Value = InputBox(“Please enter a number”)

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

End Sub

OR

Sub MyFirst_Calculator()

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

3. To change the calculator program from multiplication to something else i.e addition, subraction, division replace the * with either +, -, /,

4. Click on the green triangle to run program in Microsoft Office Excel 2007.

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: