Just +, - ,* ,%26amp; / these operations enough ,i am a beginner give full detailsHow to make a calculator project in Excel using vb?
1. 1st open a new workbook, Alt+F11 go to vba editor, on the left side, right click on a icon and choose insert userform, when click on this userform toolbox of controls appear, click the textbox button and click and drag a rectangle on the userform to create an entry box, create another textbox just underneath the 1st one.
2. click on the commandbutton on the toolbox, click and drag a rectangle to create a button on the userform, make another four for each of the calculation sign,
3. click on the label button on the toolbox, click and drag a rectangle to create a button on the userform, that would be for the displaying the result
4. click on each of the button, go to the properties window on button left(F4 to open if not already there), change the value right of caption to +, -, x, / respectively for 4 buttons
5. click on the label, go to properties and delete the value in right of caption, change the background color of this label(if like) by clicking on box right of Backcolor, palette,
6. right click on each of the calculation sign button,
for + put the following into the ';Private sub CommandButton Click()'; and ';End Sub';
Label1.Caption = TextBox1.Value * 1 + TextBox2.Value * 1
for - put the following into the ';Private sub CommandButton Click()'; and ';End Sub';
Label1.Caption = TextBox1.Value - TextBox2.Value
for x put the following into the ';Private sub CommandButton Click()'; and ';End Sub';
Label1.Caption = TextBox1.Value * TextBox2.Value
for / put the following into the ';Private sub CommandButton Click()'; and ';End Sub';
Label1.Caption = TextBox1.Value / TextBox2.Value
7. if you want to add feature to it like only calculate when both textbox have number add following line to each of the 4 sub
If TextBox1.Value = ';'; Or TextBox2.Value = ';'; Then Exit Sub
Here's a demo illustrate the above http://www.freewebs.com/swhtam/YA/myCalc鈥?/a> Alt+F11 and right click on the userform1, view code to see all the code listed above, view object to see the set up of userform1.
Please contact for more details
No comments:
Post a Comment