INTRODUCTION TO VISUAL BASIC
EDITOR
VISUAL BASIC
is a third generation event – driven programming language and integrated
development environment (IDE) from Microsoft for its Component Object
Model(COM) programming model first released in 1991 and declared legacy
during 2008.
Microsoft intended Visual Basic to be relatively easy to learn and use.
Introduction to Visual Basic Editor
Sub
a set of commands to perform a
specific task is placed into a
procedure, which can be a Function
procedure or a Sub procedure (also
known as functions and
subroutines)
Range/Cells
Range (“A1”) tells VBA the
address of the cell that we want
to refer to.
Select is a method of the
range object and select
cells/range specified in the
range object. The cell
references need to be
enclosed in double quotes.
Range/Cells
• Instead of Range, you can also use cells.
• Using cells is particularly useful when you
want to loop through ranges.
Selecting Worksheet
• To select the cell in another sheet (let’s say
Sheet2), you need to first activate Sheet2
and then select the cell in it.
Selecting a Fix Sized Range
• Code that will select the range A1:D20
• The above code takes the top – left
cell address (A1) and the bottom –
right cell address (D20) and selects
the entire range
Copying Single Cell
• To copy cell A1 and paste it into cell D1.
Excel VBA and Variables
Variable
Use to store in memory
2 Types of Variables
1. Integer
2. String
Dim
keyword goes at the start
tells the programme to set up a
variable of this name and type
Excel VBA and Variables
MyNumber
variable name
As Integer
type of variable
as a whole number
MyNumber = 10
assigning values of 10
Variable Practice:
Making Decisions: