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.
- Go to the Developer Tab in Excel. If you haven’t activated the Developer Tab then see here how to do it.
- Insert a Command Button by clicking on ‘Insert’.
- 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.
Leave a Reply