In this tutorial we are going to explain how you can
Assign a Macro to
the Command Button in the Microsoft Excel.
To assign a macro (one
or more code lines) to the command button, execute the following steps:
-
Right click CommandButton1 (make sure Design Mode is selected).
-
Click View Code.
|
|
View Code
|
The Visual Basic Editor appears.
-
Place your cursor between Private Sub CommandButton1_Click() and End Sub.
- Add the code line shown below:
Range("A1").Value = "Hello"
|
Add Code Line
|
Note: The window on the left with the name Sheet1 (Sheet1)
and ThisWorkbook is called the Project Explorer. If the Project Explorer
is not visible, click on View menu and then click on Project Explorer. If the Code window for
Sheet1 is not visible, click Sheet1 (Sheet1). You can ignore the
Option Explicit
statement for now.
- Close the Visual Basic Editor.
-
Click the command button on the sheet (make sure Design Mode is
deselected).
Result:
|
Macro Result
|
Congratulations. You've just created a macro in Excel!
No comments:
Post a Comment