ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell value controlled by button (https://www.excelbanter.com/excel-programming/312800-cell-value-controlled-button.html)

Zurn[_16_]

Cell value controlled by button
 

I want the value of a cell to increase by one every time I push
button...

is there a short code to do this?

th

--
Zur
-----------------------------------------------------------------------
Zurn's Profile: http://www.excelforum.com/member.php...fo&userid=1464
View this thread: http://www.excelforum.com/showthread.php?threadid=26722


Tom Ogilvy

Cell value controlled by button
 
for a commandbutton from the control toolbox toolbar, use the click event.

Private Sub Commandbutton1_Click()
Dim ans
if isnumeric(Range("A1").Value) then
Range("A1").Value = Range("A1").Value + 1
Else
ans = Msgbox("Value in A1 is non-numeric; enter 1?", vbYesNo)
if ans = vbYes then
Range("A1").Value = 1
end if
End if
End Sub

For a forms toolbar button

Sub IncrValue()
Dim ans
if isnumeric(Range("A1").Value) then
Range("A1").Value = Range("A1").Value + 1
Else
ans = Msgbox("Value in A1 is non-numeric; enter 1?", vbYesNo)
if ans = vbYes then
Range("A1").Value = 1
end if
End if
End Sub

Assign this macro to the button.
--
Regards,
Tom Ogilvy

"Zurn" wrote in message
...

I want the value of a cell to increase by one every time I push a
button...

is there a short code to do this?

thx


--
Zurn
------------------------------------------------------------------------
Zurn's Profile:

http://www.excelforum.com/member.php...o&userid=14645
View this thread: http://www.excelforum.com/showthread...hreadid=267220




SOS[_37_]

Cell value controlled by button
 

Hi Zurn,

Try this

Private Sub CommandButton1_Click()
Range("A1").Value = Range("A1").Value + 1
End Sub

HTH

Regards

Seamu

--
SO
-----------------------------------------------------------------------
SOS's Profile: http://www.excelforum.com/member.php...nfo&userid=540
View this thread: http://www.excelforum.com/showthread.php?threadid=26722



All times are GMT +1. The time now is 05:45 PM.

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