Command Buttons

  • Thread starter Command Button Calculations
  • Start date
C

Command Button Calculations

I am trying to insert a command button so that when the user fills out the
form and clicks the button, an amount will calculate. For example, the sales
price is in A1, when the user clicks the command button, the sales price will
be divided by 1000 then divided by 2 and the answer will appear in A5. Can
anyone help????
 
G

Gord Dibben

You can do that with a simple formula in A5 and no command button but if you
want a button.

Assign this macro to a button from the Forms Toolbar.

Sub divide()
With ActiveSheet
.Range("A5").Value = Range("A1").Value / 2000
End With
End Sub


Gord Dibben MS Excel MVP
 
F

FSt1

Sub xlcalcit()
Dim c As Double
c = [A1].Value
c = c / 1000
c = c / 2
[A5].Value = c
End Sub

regards
FSt1
 
D

Dave Peterson

Just a minor typing change.

Sub divide()
With ActiveSheet
.Range("A5").Value = .Range("A1").Value / 2000
End With
End Sub

I added the dot in front of the .range("A1")... stuff.

But even without this dot, the code would work fine -- since you're using the
activesheet and the code is in a general module.

But it's never a bad idea to qualify ranges/objects <vbg>.
 
G

Gord Dibben

Thanks Dave.


Gord

Just a minor typing change.

Sub divide()
With ActiveSheet
.Range("A5").Value = .Range("A1").Value / 2000
End With
End Sub

I added the dot in front of the .range("A1")... stuff.

But even without this dot, the code would work fine -- since you're using the
activesheet and the code is in a general module.

But it's never a bad idea to qualify ranges/objects <vbg>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top