Increasing and decreasing cell values

  • Thread starter Thread starter MJKelly
  • Start date Start date
M

MJKelly

Hi,

I have a column of numbers which I need to adjust. I will need to add
and subtract from the original value (+1 or -1). I would like to
assign code to a button, so when it is pressed 1 is added to the cell
to the left (and another button would reduce the value by 1). I think
I could do this, hower with a list of 40 or so numbers in the column,
I wanted to use the same code for each + button and a second macro for
the - buttons. This is what I am not sure of? It just seems really
long winded to write specific code for each cell. Can you offset from
the buttons position for example?

kind regards,
Matt
 
Assuming your button's name is CommandButton1, use this click event to add 1
for each button click...

Private Sub CommandButton1_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

For the minus 1 button, use the same code, but change the plus sign to a
minus sign.

Private Sub CommandButton2_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

Just select the cell you want to increment or decrement before clicking the
buttons.

Rick
 
Assuming your button's name is CommandButton1, use this click event to add 1
for each button click...

Private Sub CommandButton1_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

For the minus 1 button, use the same code, but change the plus sign to a
minus sign.

Private Sub CommandButton2_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

Just select the cell you want to increment or decrement before clicking the
buttons.

Rick
Thanks Rick.

Would this work for multiple selections at the same time?

Matt
 
Assuming your button's name is CommandButton1, use this click event to
Thanks Rick.

Would this work for multiple selections at the same time?

No, but this should...

Private Sub CommandButton1_Click()
Dim C As Range
For Each C In Selection
C.Value = C.Value + 1
Next
End Sub

Rick
 
No, but this should...

Private Sub CommandButton1_Click()
Dim C As Range
For Each C In Selection
C.Value = C.Value + 1
Next
End Sub

Rick

Rick,

That works brilliantly, thanks,

Matt
 

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

Back
Top