Macro to Increment a Cell's Value By 1

  • Thread starter Thread starter Dave
  • Start date Start date
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
 
Try this Dave

Sub test()
If IsNumeric(ActiveCell.Value) Then
ActiveCell.Value = ActiveCell.Value + 1
End If
End Sub
 
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
 
Back
Top