Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Increasing and decreasing numbers by 5% ....also showing a loss Karen Excel Discussion (Misc queries) 2 April 12th 09 03:44 AM
increasing or decreasing a cell gma Excel Worksheet Functions 16 March 5th 09 12:48 AM
shortcut for increasing or decreasing the number of decimals JorisBK Excel Worksheet Functions 1 April 8th 08 03:44 PM
increasing and decreasing a value in a cell cwal Excel Worksheet Functions 6 April 14th 06 06:55 PM
Decreasing/Increasing decimal places Daniel Bonallack[_2_] Excel Programming 1 July 17th 03 04:05 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"