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
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.