ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Making command button code "more flexible" (https://www.excelbanter.com/excel-programming/273474-re-making-command-button-code-more-flexible.html)

John Wilson

Making command button code "more flexible"
 
jamison,

Will this work for you???

mycount = Range("e" & ActiveCell.Row) + 1
Range("e" & ActiveCell.Row) = mycount

John

Jamison wrote:

I have command buttons in one column, that when clicked
add 1 to the value in an adjacent column. As of now the
code is very specific, here is the code for the buttons in
cells A4 and A5:
__________________________________
Private Sub CommandButton1_Click()
mycount = Range("e4") + 1
Range("e4") = mycount
End Sub

Private Sub CommandButton2_Click()
mycount = Range("e5") + 1
Range("e5") = mycount
End Sub
____________________________________

I would like to make it more flexible so that it adds 1 to
the cell in column e that is in the same row, instead of
having to list the row #. For example, it should add 1 to
the cell e"samerow", instead if creating twenty different
pieces of code like "e6", one for "e7", etc.,

I hope this makes sense.

Thanks.



jamison

Making command button code "more flexible"
 
Yes, that worked great. Thanks!
-----Original Message-----
jamison,

Will this work for you???

mycount = Range("e" & ActiveCell.Row) + 1
Range("e" & ActiveCell.Row) = mycount

John

Jamison wrote:

I have command buttons in one column, that when clicked
add 1 to the value in an adjacent column. As of now

the
code is very specific, here is the code for the buttons

in
cells A4 and A5:
__________________________________
Private Sub CommandButton1_Click()
mycount = Range("e4") + 1
Range("e4") = mycount
End Sub

Private Sub CommandButton2_Click()
mycount = Range("e5") + 1
Range("e5") = mycount
End Sub
____________________________________

I would like to make it more flexible so that it adds 1

to
the cell in column e that is in the same row, instead of
having to list the row #. For example, it should add 1

to
the cell e"samerow", instead if creating twenty

different
pieces of code like "e6", one for "e7", etc.,

I hope this makes sense.

Thanks.


.



All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com