How to Make a Calculator in Excel (with Easy Steps)

Get FREE Advanced Excel Exercises with Solutions!

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.

how to make a calculator in excel

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

Input Command Button to make a calculator in excel

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

Create VBA Macro and Attach to the Buttons to make a calculator in excel

  • 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
  • For Clear Output button, insert the code below:
Private Sub CommandButton6_Click()
Range("D6").ClearContents
End Sub

Code for Clear button and Output clear button

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

Test Calculator Operation in Excel

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

Final step of make calculator in Excel

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.


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

What is ExcelDemy?

ExcelDemy - Learn Excel & Get Excel Solutions Center provides online Excel training , Excel consultancy services , free Excel tutorials, free support , and free Excel Templates for Excel professionals and businesses. Feel free to contact us with your Excel problems.

Tags:

Rubayed Razib Suprov
Rubayed Razib Suprov

Rubayed Razib, holding a BSC degree in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, serves as a devoted member of the ExcelDemy project. He has contributed significantly by authoring numerous articles and showcasing proficiency in VBA. Razib efficiently automates Excel challenges using VBA macros and actively participates in the ExcelDemy forum, providing valuable solutions for user interface challenges. Apart from creating Excel tutorials, he is interested in Data Analysis with MS Excel,... Read Full Bio

2 Comments
  1. FOLLOWED YOUR STEPS BUT IT DIDN’T WORK FOR ME – GIVES ME AN AMBIGUOUS NAME DETECTED:CLEARCELLS ERROR AND NONE OF THE BUTTONS WORK

    • Dear April
      Thanks for your concern. There were some minor formatting issues with the VBA codes. Sorry for the inconvenience. We have updated our article. If you follow now, you will get the perfect calculator.
      Thanks for your help
      Regards,
      Joyanta Mitra
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo