View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default 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