VBA stands for Visual Basic for Applications, is an event-driven programming language from Microsoft.
In this tutorial, you will learn following,
- How to Access the Visual Basic Editor?
- How to add and rename a command button?
- How to write VBA Code for the command button?
How to Access the Visual Basic Editor?
Before you can start writing code, you first need to open Visual Basic Editor.
Step 1 – First, enable ‘Developer’ menu in Excel, to do the same, click File → Options.
Step 2 – Click ‘Customize Ribbon’ tab and check ‘Developer’. Click ‘OK’.
Step 3 – The ‘Developer’ tab appears in the menu bar. Click ‘Visual Basic’ to open Visual Basic Editor.
How to add and rename a command button?
Step 4 – Click Insert → Select button
Step 5 – Right-click on button and choose ‘Properties’
Step 6 – Edit name and caption for the button as shown below
How to write VBA Code for the command button?
Step 7 – Double-click on the button and the sub-procedure will be displayed.
Step 8 – Add code ‘MsgBox “Hellow”
Step 9 – Click the button and the result will be as shown below.