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.
How to Make a Calculator in Excel (with Easy Steps)
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.
Read More: How to Create a Calculator Using Macros in Excel
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.
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").ValueEnd 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 ThenRange("D6") = Range("C4").Value - Range("E4").ValueElseRange("D6") = Range("D6").Value - Range("E4").ValueEnd IfEnd 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").ValueEnd 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").ValueEnd Sub
- Repeat the same procedure for the Clear All button and enter the below code for that button.
Private Sub CommandButton5_Click()Range("C4").ClearContentsRange("E4").ClearContentsRange("D6").ClearContentsEnd Sub
- For Clear Output button, insert the code below:
Private Sub CommandButton6_Click()Range("D6").ClearContentsEnd 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.
Download Practice Workbook
Download this practice sheet to practice while you are reading this article.
How to Make a Calculator.xlsm
Conclusion
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.
Related Articles
- How to Use Excel VBA Userform
- Excel VBA: Create a Progress Bar While Macro Is Running
- How to Create Cascading Combo Boxes in Excel VBA User Form