![]() |
Macro to Increment a Cell's Value By 1
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 |
Macro to Increment a Cell's Value By 1
Try this Dave
Sub test() If IsNumeric(ActiveCell.Value) Then ActiveCell.Value = ActiveCell.Value + 1 End If End Sub -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "Dave" wrote in message ... 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 |
Macro to Increment a Cell's Value By 1
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 -- HTH Bob Phillips "Dave" wrote in message ... 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 |
All times are GMT +1. The time now is 10:06 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com