SlideShare a Scribd company logo
Intro to VBA
Programming
Ivey Technology Club
Intro to VBA Programming

Agenda
 Variables




Types
Declaration
Assignment

 Functions/Subroutines



Parameters
Returning values

 Loops



While
For
Intro to VBA Programming

Agenda
 Variables




Types
Declaration
Assignment

 Functions/Subroutines



Parameters
Returning values

 Loops



While
For
Intro to VBA Programming

 You‟ve

seen variables before

X

=5
Y=X+3
 Variables

can be reused and changed

X

=5
X=2
X=X+7
 The

same principles apply in
programming
Variables

Functions

Loops
Intro to VBA Programming

 Computers

are stupid

 Must

tell them exactly what to do
 The more we tell them, the faster they run
 Each

language does this differently

 We

will focus on VBA

Variables

Functions

Loops
Intro to VBA Programming

 All

variables should be declared first

 This

will prevent hard to find errors

 It

is not required that you do so, but HIGHLY
encouraged

 To

force yourself, use “Option Explicit” at the
beginning of VBA files

Variables

Functions

Loops
Intro to VBA Programming

 To

declare a variable in VBA, the basic
structure is:
Dim <name> as <type>
Ex. Dim X as Integer

Variables

Functions

Loops
Intro to VBA Programming

 Dim

means “new Dimension”

 Fancy

VBA way of saying new variable

 When

declaring a variable, you should
know what it will be used for

 Different

variable types are used to store
different data

Variables

Functions

Loops
Intro to VBA Programming

 Types

include:

 Integer

(whole numbers like 3)
 Float (decimal numbers like 1.25)
 Double (just like float, can store wider range
of values)
 Characters (like „a‟)
 String (a number of characters in a row such
as “Ivey”)
 MANY

Variables

more

Functions

Loops
Intro to VBA Programming

 Types

include:

 Integer

(whole numbers like 3)
 Float (decimal numbers like 1.25)
 Double (just like float, can store wider range
of values)
 Characters (like „a‟)
 String (a number of characters in a row such
as “Ivey”)
 MANY

Variables

more

Functions

Loops
Intro to VBA Programming

 To

assign a value to a use the “=“
operator
 Ex.

Dim x As Integer (declare the variable)
x=5

Variables

Functions

Loops
Intro to VBA Programming

Agenda
 Variables




Types
Declaration
Assignment

 Functions/Subroutines



Parameters
Returning values

 Loops



While
For
Intro to VBA Programming

Functions
 Take

in input, process it, and produce
output

Variables

Functions

Loops
Intro to VBA Programming

 Functions
 General

must also be declared

format of function declaration:

Function <name>(ByVal <parameterName> As <type>) As <returnType>

 Subroutines

are declared the same way,
but do not have a return type

Variables

Functions

Loops
Intro to VBA Programming

 ByVal

refers to “by value”

 This

will make a copy of the variable and its
value

 ByRef

could also be used

 This

 Don‟t

will modify the original variable

worry too much about this for now

Variables

Functions

Loops
Intro to VBA Programming

 To

explicitly return a value from a
function, assign the return value to the
function name itself

Variables

Functions

Loops
Intro to VBA Programming

 Subroutines

are the same as functions,
except for 2 important differences:
1.

They do not have explicit return types

2.

They cannot be used directly in the
spreadsheet

Variables

Functions

Loops
Intro to VBA Programming

Agenda
 Variables




Types
Declaration
Assignment

 Functions/Subroutines



Parameters
Returning values

 Loops



While
For
Intro to VBA Programming

Loops
 Loops

allow us to repeatedly perform the
same task easily

 There

are different kinds of loops
including:
 While
 Until
 For

Variables

Functions

Loops
Intro to VBA Programming

 “While”

true

 “Until”

true

loops while a certain condition is

loops until a certain condition is

 “For”

loops for a specified number of
iterations

Variables

Functions

Loops
Intro to VBA Programming

Questions, anyone ?

More Related Content

PPTX
Vba part 1
PPTX
Using Vba Excel
PPTX
VBA Classes from Chandoo.org - Course Brochure
PDF
Online Advance Excel & VBA Training in India
PDF
2016 Excel/VBA Notes
PPTX
E learning excel vba programming lesson 4
PPTX
Introduction to Excel VBA/Macros
PDF
Vba part 1
Vba part 1
Using Vba Excel
VBA Classes from Chandoo.org - Course Brochure
Online Advance Excel & VBA Training in India
2016 Excel/VBA Notes
E learning excel vba programming lesson 4
Introduction to Excel VBA/Macros
Vba part 1

What's hot (20)

PPTX
E learning excel vba programming lesson 3
PPTX
Vba Class Level 1
PPTX
E learning excel vba programming lesson 2
PPTX
Vba introduction
PDF
Excel VBA programming basics
PPT
E learning excel vba programming lesson 1
PPTX
DOCX
Excel vba
PPTX
VBA
PPS
Transforming Power Point Show with VBA
PPTX
Vba Class Level 3
DOCX
Advance MS Excel
PPT
AVB201.2 Microsoft Access VBA Module 2
PPT
Creating A User‑Defined Function In Excel Using Vba
PDF
Visual Basics for Application
PPT
AVB201.1 MS Access VBA Module 1
PPTX
07 java variables
PDF
Access tips access and sql part 2 putting vba and sql together
DOCX
Fieldsymbols
PPTX
Operators in java By cheena
E learning excel vba programming lesson 3
Vba Class Level 1
E learning excel vba programming lesson 2
Vba introduction
Excel VBA programming basics
E learning excel vba programming lesson 1
Excel vba
VBA
Transforming Power Point Show with VBA
Vba Class Level 3
Advance MS Excel
AVB201.2 Microsoft Access VBA Module 2
Creating A User‑Defined Function In Excel Using Vba
Visual Basics for Application
AVB201.1 MS Access VBA Module 1
07 java variables
Access tips access and sql part 2 putting vba and sql together
Fieldsymbols
Operators in java By cheena
Ad

Similar to Intro to Excel VBA Programming (20)

PPTX
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
PPT
AVB201.1 Microsoft Access VBA Module 1
PPTX
Unit 5: Variables
PDF
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
PDF
Getting started with Microsoft Excel Macros
PPT
Financial modeling sameh aljabli lecture 6
PPTX
Excel VBA.pptx
PDF
Ma3696 Lecture 3
PDF
Programming inexcelvba anintroduction
PDF
Vbabook ed2
PDF
Excel-Quick-Reference-Guide.pdf
DOC
Excel Vba Basic Tutorial 1
PPTX
Learn VBA Training & Advance Excel Courses in Delhi
PPTX
DOC
VBA Training Contents
PPTX
ExcelMacrosAndVBA-PP.pptx rqererrwtwtwtwe
PDF
PDF
MA3696 Lecture 9
PDF
Vba primer
PPT
Ppt lesson 05
Excel 2016 VBA PPT Slide Deck - For Basic to Adavance VBA Learning
AVB201.1 Microsoft Access VBA Module 1
Unit 5: Variables
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
Getting started with Microsoft Excel Macros
Financial modeling sameh aljabli lecture 6
Excel VBA.pptx
Ma3696 Lecture 3
Programming inexcelvba anintroduction
Vbabook ed2
Excel-Quick-Reference-Guide.pdf
Excel Vba Basic Tutorial 1
Learn VBA Training & Advance Excel Courses in Delhi
VBA Training Contents
ExcelMacrosAndVBA-PP.pptx rqererrwtwtwtwe
MA3696 Lecture 9
Vba primer
Ppt lesson 05
Ad

Recently uploaded (20)

PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Pre independence Education in Inndia.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
From loneliness to social connection charting
PPTX
Onica Farming 24rsclub profitable farm business
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
Week 4 Term 3 Study Techniques revisited.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Pre independence Education in Inndia.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Pharma ospi slides which help in ospi learning
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
O7-L3 Supply Chain Operations - ICLT Program
Open Quiz Monsoon Mind Game Prelims.pptx
Revamp in MTO Odoo 18 Inventory - Odoo Slides
102 student loan defaulters named and shamed – Is someone you know on the list?
From loneliness to social connection charting
Onica Farming 24rsclub profitable farm business
Cardiovascular Pharmacology for pharmacy students.pptx

Intro to Excel VBA Programming

  • 2. Intro to VBA Programming Agenda  Variables    Types Declaration Assignment  Functions/Subroutines   Parameters Returning values  Loops   While For
  • 3. Intro to VBA Programming Agenda  Variables    Types Declaration Assignment  Functions/Subroutines   Parameters Returning values  Loops   While For
  • 4. Intro to VBA Programming  You‟ve seen variables before X =5 Y=X+3  Variables can be reused and changed X =5 X=2 X=X+7  The same principles apply in programming Variables Functions Loops
  • 5. Intro to VBA Programming  Computers are stupid  Must tell them exactly what to do  The more we tell them, the faster they run  Each language does this differently  We will focus on VBA Variables Functions Loops
  • 6. Intro to VBA Programming  All variables should be declared first  This will prevent hard to find errors  It is not required that you do so, but HIGHLY encouraged  To force yourself, use “Option Explicit” at the beginning of VBA files Variables Functions Loops
  • 7. Intro to VBA Programming  To declare a variable in VBA, the basic structure is: Dim <name> as <type> Ex. Dim X as Integer Variables Functions Loops
  • 8. Intro to VBA Programming  Dim means “new Dimension”  Fancy VBA way of saying new variable  When declaring a variable, you should know what it will be used for  Different variable types are used to store different data Variables Functions Loops
  • 9. Intro to VBA Programming  Types include:  Integer (whole numbers like 3)  Float (decimal numbers like 1.25)  Double (just like float, can store wider range of values)  Characters (like „a‟)  String (a number of characters in a row such as “Ivey”)  MANY Variables more Functions Loops
  • 10. Intro to VBA Programming  Types include:  Integer (whole numbers like 3)  Float (decimal numbers like 1.25)  Double (just like float, can store wider range of values)  Characters (like „a‟)  String (a number of characters in a row such as “Ivey”)  MANY Variables more Functions Loops
  • 11. Intro to VBA Programming  To assign a value to a use the “=“ operator  Ex. Dim x As Integer (declare the variable) x=5 Variables Functions Loops
  • 12. Intro to VBA Programming Agenda  Variables    Types Declaration Assignment  Functions/Subroutines   Parameters Returning values  Loops   While For
  • 13. Intro to VBA Programming Functions  Take in input, process it, and produce output Variables Functions Loops
  • 14. Intro to VBA Programming  Functions  General must also be declared format of function declaration: Function <name>(ByVal <parameterName> As <type>) As <returnType>  Subroutines are declared the same way, but do not have a return type Variables Functions Loops
  • 15. Intro to VBA Programming  ByVal refers to “by value”  This will make a copy of the variable and its value  ByRef could also be used  This  Don‟t will modify the original variable worry too much about this for now Variables Functions Loops
  • 16. Intro to VBA Programming  To explicitly return a value from a function, assign the return value to the function name itself Variables Functions Loops
  • 17. Intro to VBA Programming  Subroutines are the same as functions, except for 2 important differences: 1. They do not have explicit return types 2. They cannot be used directly in the spreadsheet Variables Functions Loops
  • 18. Intro to VBA Programming Agenda  Variables    Types Declaration Assignment  Functions/Subroutines   Parameters Returning values  Loops   While For
  • 19. Intro to VBA Programming Loops  Loops allow us to repeatedly perform the same task easily  There are different kinds of loops including:  While  Until  For Variables Functions Loops
  • 20. Intro to VBA Programming  “While” true  “Until” true loops while a certain condition is loops until a certain condition is  “For” loops for a specified number of iterations Variables Functions Loops
  • 21. Intro to VBA Programming Questions, anyone ?