0% found this document useful (0 votes)
28 views

Introduction To Excel VBA: Hkcareers Beginners Manual

The document introduces Excel VBA by explaining what macros are and providing a step-by-step guide to creating a simple macro in Excel. It covers accessing the VBA editor, recording a macro, assigning the macro to a button, and executing the macro. It also defines some key VBA terms.

Uploaded by

Hay Kwong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Introduction To Excel VBA: Hkcareers Beginners Manual

The document introduces Excel VBA by explaining what macros are and providing a step-by-step guide to creating a simple macro in Excel. It covers accessing the VBA editor, recording a macro, assigning the macro to a button, and executing the macro. It also defines some key VBA terms.

Uploaded by

Hay Kwong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Introduction to Excel VBA

HKCAREERS BEGINNERS MANUAL


HKCareers Free Resource

TABLE OF CONTENTS

1. Introduction
2. VBA Overview
3. Excel Macros
4. Excel Terms
5. VBA Macro Comments
6. VBA Message Box
7. VBA Input Box
8. VBA- Variables
9. VBA- Constants
10.VBA- Operators

We help university students to get into Investment Banks, Banks, Property/Conglomerate and Big4s.
Prepared by HKCareers | IG: hkcareers | Facebook: hkcareers | Website: hkcareers.hk/coaching
HKCareers Free Resource

With Excel VBA you can automate tasks in Excel by writing so called macros. In this chapter,
we will look at the step-wise procedure to create a simple macro.

Accessing the VBA Editor

To open a VBA window, press "ALT+F11" in your Excel window. The screenshots below
should be able to guide you through the steps.

Step 1: Enable the 'Developer' menu in Excel by clicking on File → Options

Step 2: Drill down on ‘Customize the Ribbon’ tab → check 'Developer' tab → Click 'OK'.
(you can locate the Developer tab below the View tab)

*Source: Google

Step 3: You will now see the 'Developer' ribbon in the menu bar

*Source: Google

We help university students to get into Investment Banks, Banks, Property/Conglomerate and Big4s.
Prepared by HKCareers | IG: hkcareers | Facebook: hkcareers | Website: hkcareers.hk/coaching
HKCareers Free Resource

*Source: Google

Step 4: Click the 'Visual Basic' button to open the VBA Editor.

*Source: Google

Step 5: Start scripting by adding a button. To assign a macro (one or more code lines) to the
command button, execute the following steps.

Click Insert → Select the button

*Source: Google

Step 6: Right-click and select 'Properties'

We help university students to get into Investment Banks, Banks, Property/Conglomerate and Big4s.
Prepared by HKCareers | IG: hkcareers | Facebook: hkcareers | Website: hkcareers.hk/coaching
HKCareers Free Resource

*Source: Google

Step 7: Edit the Name and Caption as shown in the following screenshot.

*Source: Google

Step 8: Now double-click the button and the sub-procedure outline will be displayed as
shown in the following screenshot.

We help university students to get into Investment Banks, Banks, Property/Conglomerate and Big4s.
Prepared by HKCareers | IG: hkcareers | Facebook: hkcareers | Website: hkcareers.hk/coaching
HKCareers Free Resource

Step 9: Start coding by simply adding a message.

*Source: Google

Step 10: Click the button to execute the sub-procedure. The output of the sub-procedure is
shown in the following screenshot.

*Source: Google

VBA ─ EXCEL TERMS

In this section, we will discuss the commonly used excel VBA terminologies which we will
encounter in the following sections. Hence it is important to understand them at this stage.

Line of Code

This a VBA instruction as we have seen above. Generally speaking, it performs one task.

Sub

A sub is made up of one or more lines of code. We create a sub so that VBA will process the
instructions we give it. To do this we get VBA to Run the sub. When we “Run” the sub,
VBA goes through all the lines of code and carries out the appropriate actions. A macro and a
sub are essentially the same thing.

Modules

We help university students to get into Investment Banks, Banks, Property/Conglomerate and Big4s.
Prepared by HKCareers | IG: hkcareers | Facebook: hkcareers | Website: hkcareers.hk/coaching
HKCareers Free Resource

Modules is the area where the code is written. A module contains subs which in turn contain
lines of code. There is no reasonable limit to the number of modules in a workbook or the
number of subs in a module that can be created.

*Source: Google

To insert a Module, navigate to Insert → Module. Once a module is inserted 'Module1' is


created.

*Source: Google

Within the modules, we can write VBA code and the code is written within a Procedure. A
Procedure is a unit of code enclosed either between the Sub and End Sub statement or
between the Function and End Function statements.

Procedure
Procedures are a group of statements executed as a whole, which instructs Excel how to
perform a specific task. The task performed can be a very simple or a very complicated task.
However, it is a good practice to break down complicated procedures into smaller ones.

We help university students to get into Investment Banks, Banks, Property/Conglomerate and Big4s.
Prepared by HKCareers | IG: hkcareers | Facebook: hkcareers | Website: hkcareers.hk/coaching

You might also like