Macro to Increment a Cell's Value By 1

D

Dave

Sorry if this is a stupid question.

I would like to have a macro activated by a button. You
would select a cell (for example, with "2" in it), click
the button, and the value in the cell would be incremented
by 1 (in the example, it would now be "3"). Is is possible
to do, and can anyone tell me how to do it?

Thanks,

Dave
 
R

Ron de Bruin

Try this Dave

Sub test()
If IsNumeric(ActiveCell.Value) Then
ActiveCell.Value = ActiveCell.Value + 1
End If
End Sub
 
B

Bob Phillips

Dave,

Public Sub Increment()
ActiveCell.Value = ActiveCell.Value + 1
End Sub


And here's some code to add a button to the formatting menu

Sub AddMenu()
Dim oCb As CommandBar
Dim oCtl As CommandBarButton

Set oCb = Application.CommandBars("Formatting")
With oCb
Set oCtl = .Controls.Add(Type:=msoControlButton, temporary:=True)
oCtl.Caption = "Increment"
oCtl.BeginGroup = True
oCtl.FaceId = 137
oCtl.OnAction = "Increment"
End With
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

Top