26 May 2012

Increment a Cell value using button from macro in MS Excel

ms excel

Using a button , you can increment any cell value in Microsoft Excel.

For Excel 2003:

On the top menu ,
  • Go to View => Toolbars => Choose Control Toolbox (if not checked)
  • From the control toolbox, Select Design Mode to activate .
  • Then,From the control toolbox , select Command Button and draw it on the sheet.
  • Right Click on the button and choose View Code
[note: Design mode should be active in the control toolbox]

Add this line of code in the middle of the given lines.

Selection.Value = Selection.Value + 1

After adding it, the tolal code will look like this :
Private Sub CommandButton1_Click()
Selection.Value = Selection.Value + 1
End Sub

Close the Editor.

To change the label of the button , right click on button , select properties.
Look for Caption and enter your desired text , for example : increment

Done.

Now , from control toolbox , unckech the design Mode (Exit Design mode).

Now select a cell and click the button .

This will result in increment a value of that selected cell.


(If you found this article useful then share with your friends.)

No comments: