|
|
Although MS Excel can perform all kinds of
calculations, but isn't it cool to program a customized VBA calculator that can
perform some basic calculations? Today I was a bit exhausted so I let my son
handled VB Today. Initially he as a bit reluctant but after some persuasions he
finally agreed to do it, and he programmed a nice little VBA calculator that can
perform some basic arithmetic operations. Here is the VBA program:
Private Sub CommandButton1_Click()
Range("A3").Value = Range("A1").Value + Range("A2").Value
End Sub
Private Sub CommandButton2_Click()
Range("A3").Value = Range("A1").Value - Range("A2").Value
End Sub
Private Sub CommandButton3_Click()
Range("A3").Value = Range("A1").Value * Range("A2").Value
End Sub
Private Sub CommandButton4_Click()
Range("A3").Value = Range("A1").Value / Range("A2").Value
End Sub
|
Explanation:
This a very simple
program which I think don't need much explanations. Basically you
create four command buttons that specifically designed to perform
addition, subtraction, division and multiplication operations. The
function Range("A1") is to specify the location of the cell that
displays the values. The answer in cell A3 will display the result
of addition, subtraction, division or multiplication depending on
which button you press.
|
|