Cell value controlled by button

  • Thread starter Thread starter Zurn
  • Start date Start date
Z

Zurn

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
 
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.
 
Hi Zurn,

Try this

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

HTH

Regards

Seamu
 
Sub BtnIncreaseValue_CLick()
cells(1,1).value=cells(1,1).value+1
End SUb
 

Ask a Question

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.

Ask a Question

Back
Top