The calculator is a part and parcel of our daily life. We can use the calculator directly inside Excel without switching to other applications or manual calculations. In this article, we present 4 step by step procedures to make a calculator in Excel in a detailed manner.
Download Practice Workbook
Download this practice sheet to practice while you are reading this article.
Step-by-Step Procedure to Make a Calculator in Excel
The process of making a calculator in Excel involves creating an outline and then attaching code to it. And then finalize the calculator by testing them with various numbers. For avoiding any compatibility issues, use MS Excel 365 edition.
Step 1: Create Calculator Outline
Before we delve into creating the calculator button and assign various codes to it, we must first create the outline of the calculator beforehand.
- To begin with, we need to create the outline of our calculator first.
- For this, we arranged the input and the output cells as shown below.
Step 2: Input Command Button
After creating the basic outline, now we can create various buttons for the calculator using the command button.
- To add a command button, go to the Developer > Insert > Command Button (ActiveX Control).
- After then you will notice that there is a new draw icon.
- Using that icon, draw the shape of your Command Button box.
- Here we draw a medium-sized box and then release the cursor.
- The command box right now has a caption within it. We need to alter the caption.
- To alter the caption, right-click on the box and select Properties from the context menu.
- In the properties menu, click on the caption and then type “+”.
- Click on the cross in the corner of the box to close it.
- Right after this, we will notice that the command button is now present with a modified caption.
- Repeat the same process for the rest of the buttons shown below.
- The different buttons will denote different operations.
- Clear All button will clear everything(the inputs and outputs)
- The Clear Output will clear only the output value so that you can restart the operation immediately.
- Hence we completed the button layout in excel for now.
- How to Add Trailing Zeros in Excel (2 Easy Ways)
- Count Words in Excel (6 Easy Methods)
- How to Do Bookkeeping for Small Business in Excel (Step-by-Step)
- Make Games in Excel (with Easy Steps)
- How to Fix Formula in Excel (9 Easy Methods)
Step 3: Create VBA Macro and Attach to the Buttons
Now we can create VBA codes and attach them to individual buttons.
- For this, right-click on the first button created and then select View Code from the context menu.
- There will be a code editor window where you need to type the below code.
Private Sub CommandButton1_Click() Range("D6") = Range("C4").Value + Range("D6").Value + Range("E4").Value End Sub
- Now, move on to the next button “-”.
- Right-click on it and select View Code from the context menu.
- In the window, type the below code and then close it using the close or cross icon corner of the window.
Private Sub CommandButton3_Click() If Range("D6").Value = 0 Then Range("D6") = Range("C4").Value - Range("E4").Value Else Range("D6") = Range("D6").Value - Range("E4").Value End If End Sub
- Repeat the same procedure for the multiplication button and enter the below code for that button.
Private Sub CommandButton2_Click() Range("D6") = Range("C4").Value * Range("E4").Value End Sub
- Repeat the same procedure for the division button and enter the below code for that button.
Private Sub CommandButton4_Click() Range("D6") = Range("C4").Value / Range("E4").Value End Sub
Repeat the same procedure for the Clear All button and enter the below code for that button.
Private Sub CommandButton5_Click() Range("C4").ClearContents Range("E4").ClearContents Range("D6").ClearContents End Sub
- After entering all of that code, we can see that the buttons are now fully functioning and ready to put into operation.
Step 4: Test Calculator Operation
Every operation or project needs specific testing in order to make them reliable. Hence we need to test out the calculator to make sure that the calculator is working perfectly.
- As we now have the buttons, we can now use them to test various mathematical operations.
- For this, enter 110 and 10 as Input 1 and Input 2 in cells C4 and E4
- To estimate the sum of them, click on the “+” icon.
- After clicking on the + sign, the output will be shown as 120.
- Now, we want to conduct a new operation, for this clears the output values by pressing the Clear Output option.
- After this, having the same input as before, click on the – icon.
- The output will be shown as 100 in cell D6.
Observing these examples, we can ascertain that the calculator is working as expected.
I hope all of these simple methods mentioned above will now help you to apply them in your Excel spreadsheets when you have to make a calculator. For this problem, a workbook is available to download where you can practice these methods. Feel free to ask any questions or feedback through the comment section. Any suggestion for the betterment of the Exceldemy community will be highly appreciable.
- How to Recalculate in Excel (3 Effective Methods)
- Force Recalculation with VBA in Excel
- How to Create Toggle Button on Excel VBA UserForm
- Calculate Root Mean Square Error in Excel
- How to Calculate APR in Excel (3 Simple Methods)
- Calculate Cost of Funds in Excel (with Easy Steps)
- How to Calculate WACC in Excel (with Easy Steps)