Lesson#184: Entered value divided by 100 with a button in VBA

Lesson#184: Entered value divided by 100 with a button in VBA

Here I shall show how entered value can be divided by 100 with a button in VBA.

  1. Go to the Developer Tab in Excel. If you haven’t activated the Developer Tab then see here how to do it.
  2. Insert a Command Button by clicking on ‘Insert’.
  3. Create a button on the sheet and double-click to enter the code.

Here is the VBA macro that will automatically divide the value of the active cell by 100 when a command button is clicked:

Private Sub CommandButton1_Click()
    ' Get the active cell
    Dim cell As Range
    Set cell = Application.ActiveCell

    ' If the cell is numerical, divide its value by 100
    If IsNumeric(cell.Value) Then
        cell.Value = cell.Value / 100
    End If
End Sub

To use this macro, place it in a module in your VBA project and create a command button on your worksheet. Then, select the command button and assign the CommandButton1_Click macro to it by clicking the “Assign Macro” button in the “Control” ribbon.

Now, when you click the command button, the value of the active cell will be divided by 100 if it is numerical.

See also  Lesson#70: Where to start VBA?

Hi! I am Puspendu. I am the founder and author of Excelabcd. I am little creative person, blogger and Excel-maniac guy. I hope you enjoy my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

*