You are on page 1of 5

Page |1

TOPIC 1 – Introduction

VBA - Overview
VBA stands for Visual Basic for Applications an event-driven programming language from
Microsoft that is now predominantly used with Microsoft office applications such as
MSExcel, MS-Word, and MS-Access.
It helps techies to build customized applications and solutions to enhance the capabilities of
those applications. The advantage of this facility is that you NEED NOT have visual basic
installed on our PC, however, installing Office will implicitly help in achieving the purpose.
You can use VBA in all office versions, right from MS-Office 97 to MS-Office 2013 and also
with any of the latest versions available. Among VBA, Excel VBA is the most popular. The
advantage of using VBA is that you can build very powerful tools in MS Excel using linear
programming.

Application of VBA
You might wonder why to use VBA in Excel as MS-Excel itself provides loads of inbuilt
functions. MS-Excel provides only basic inbuilt functions which might not be sufficient to
perform complex calculations. Under such circumstances, VBA becomes the most obvious
solution.
For example, it is very hard to calculate the monthly repayment of a loan using Excel's built-
in formulas. Rather, it is easy to program a VBA for such a calculation.

Preparation of Microsoft Excel VBA

Activate developer tab in excel (Excel 2007 and up)


Go to “File”, then Click “Options”, then “Customize Ribbon” and check the “Developer” and
“OK” to enable the developer tab in excel.

Shortcut keys
Alt + F11 : Visual basic editor window
Ctrl + R Project Explorer
F4 Properties Windows
Page |2

Click new module


Type “sub groupname”
Type between Sub & End Sub
Range("a1") = 12
Then click play button (observe what happens on the excel sheet)
Next try
Range("a1:c6") = 12
Page |3

TOPIC 2 – Range Objects and Range Properties

1. Range object – same as cell in excel


Range object with cells

2. Range Properties:
a. .Value Property
MsgBox Range(“a1”).Value

b. .Text Property
MsgBox Range(“a1”).Text

c. .Row and .Column Property


MsgBox Range(“a1”).Text

d. .Select property
Range(“table_01”).Select

e. .Count Property
MsgBox Range(“table_01).Count

f. .ADDRESS PROPERTY
MsgBox Range(“a1”).Address(0,0)

g. .FORMULA PROPERTY
Range(“a1”).Formula = “=A2+A3”

h. .NUMBERFORMAT PROPERTY
Range(“a1”).NumberFormat = “0.00””mm”””

i. .FONT.BOLD, UNDERLINE OR ITALIC


Range(“a1”).Font.Bold = true
Range(“a1”).Font.Underline = true
Range(“a1”).Font.Italic = true
Page |4

EXERCISE 1
Objectives:
1. Create a Macro that types the following headers on row 1:
•ID
•First Name
•Last Name
2. Make the headers BOLD!

EXERCISE 2

Create a Macro that:


1. Enters the following data
2. Makes a1 through b1 BOLD
3. Selects cell C1
4. Now, manually create a shape that says Click Me and assign your macro to it. This is not part of
the macro, just make the shape manually.
Page |5

TOPIC 3 – Cell Objects


a. The Cell Object

Cells(1,2) = 50
Cells(1,”b”) = 50

b. Using Cells positionally within a Range


Cells(6) = 44
Range(“a1:c16”).cells(6) = 44

c. Affecting all cells in a worksheet


Cells.Font.Name = “Arial”
Cells.Font.Size = 15

d. Using Range Object with cells Object


Range(Cells(1,2),Cells(4,3)) = 4
EXERCISE 3
By default, Sheet1 on a worksheet will have a default cell font and will be zoomed to
100%.
In this exercise, the user wants a macro that formats a sheet to ideal conditions for
their work.
1. Format all cells as font "Arial"
2. Zoom in to
145%
3. Format Column D (4th column) as currency, because your company always has currency in
column D

You might also like