![]() |
Increasing and decreasing cell values
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 |
Increasing and decreasing cell values
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 "MJKelly" wrote in message ... 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 |
Increasing and decreasing cell values
On Feb 8, 3:54 pm, "Rick Rothstein \(MVP - VB\)"
wrote: 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 "MJKelly" wrote in message ... Thanks Rick. Would this work for multiple selections at the same time? Matt 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 |
Increasing and decreasing cell values
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. 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 |
Increasing and decreasing cell values
On Feb 8, 6:47 pm, "Rick Rothstein \(MVP - VB\)"
wrote: 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. 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 Rick, That works brilliantly, thanks, Matt |
All times are GMT +1. The time now is 09:54 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com