## 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.