With Excel VBA you can automate tasks in Excel by writing so called macros. In this chapter, learn how to lớn create a simple macro which will be executed after clicking on a command button. First, turn on the Developer tab.
Bạn đang xem: Quick start: create a macro
Developer Tab
To turn on the Developer tab, exeđáng yêu the following steps.
1. Right click anywhere on the ribbon, & then cliông xã Customize the Ribbon.

2. Under Customize the Ribbon, on the right side of the dialog box, select Main tabs (if necessary).
3. Cheông xã the Developer kiểm tra box.

4. Cliông chồng OK.
5. You can find the Developer tab next to the View tab.

Commvà Button
To place a comm& button on your worksheet, exeđáng yêu the following steps.
1. On the Developer tab, clichồng Insert.
2. In the ActiveX Controls group, cliông chồng Commvà Button.

3. Drag a commvà button on your worksheet.
Xem thêm: Hướng Dẫn Sử Dụng Điện Thoại Oppo F1 S, Hướng Dẫn Sử Dụng Điện Thoại Oppo F1
Assign a Macro
To assign a macro (one or more code lines) khổng lồ the command button, exedễ thương the following steps.
1. Right cliông chồng CommandButton1 (make sure Design Mode is selected).
2. Clichồng View Code.

The Visual Basic Editor appears.
3. Place your cursor between Private Sub CommandButton1_Click() & End Sub.
4. Add the code line shown below.

Note: the window on the left with the names Sheet1 (Sheet1) & ThisWorkbook is called the Project Explorer. If the Project Explorer is not visible, clichồng View, Project Explorer. If the Code window for Sheet1 is not visible, clichồng Sheet1 (Sheet1). You can ignore the Option Explicit statement for now.
5. Cthua the Visual Basic Editor.
6. Clichồng the command button on the sheet (make sure Design Mode is deselected).
Result:

Congratulations. You"ve just created a macro in Excel!
Visual Basic Editor
To open the Visual Basic Editor, on the Developer tab, clichồng Visual Basic.

The Visual Basic Editor appears.

1/9 Completed! Learn much more about creating macros > Next Chapter: MsgBox
Chapter
Learn more, it"s easy
Download Excel File
Next Chapter
Follow Excel Easy
Become an Excel Pro
Create a Macro • © 2010-2021Excel is Awesome, we"ll show you: Introduction • Basics • Functions • Data Analysis • VBA