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 ?
Ad

More Related Content

What's hot (20)

E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
Vijay Perepa
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
Ben Miu CIM® FCSI A+
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2
Vijay Perepa
 
Vba introduction
Vba introductionVba introduction
Vba introduction
Sandesh DJSAS Singh
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basics
Hang Dong
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1
Vijay Perepa
 
Vba
Vba Vba
Vba
Juhi Mahajan
 
Excel vba
Excel vbaExcel vba
Excel vba
Almeda Asuncion
 
VBA
VBAVBA
VBA
Tekish
 
Transforming Power Point Show with VBA
Transforming Power Point Show with VBATransforming Power Point Show with VBA
Transforming Power Point Show with VBA
DCPS
 
Vba Class Level 3
Vba Class Level 3Vba Class Level 3
Vba Class Level 3
Ben Miu CIM® FCSI A+
 
Advance MS Excel
Advance MS ExcelAdvance MS Excel
Advance MS Excel
acute23
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
Creating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using VbaCreating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using Vba
Chester Tugwell
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
Raghu nath
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 
07 java variables
07   java variables07   java variables
07 java variables
Zeeshan-Shaikh
 
Access tips access and sql part 2 putting vba and sql together
Access tips  access and sql part 2  putting vba and sql togetherAccess tips  access and sql part 2  putting vba and sql together
Access tips access and sql part 2 putting vba and sql together
quest2900
 
Fieldsymbols
FieldsymbolsFieldsymbols
Fieldsymbols
Nrushing Nayak
 
Operators in java By cheena
Operators in java By cheenaOperators in java By cheena
Operators in java By cheena
Chëëñå Båbü
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
Vijay Perepa
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2
Vijay Perepa
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basics
Hang Dong
 
E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1
Vijay Perepa
 
Transforming Power Point Show with VBA
Transforming Power Point Show with VBATransforming Power Point Show with VBA
Transforming Power Point Show with VBA
DCPS
 
Advance MS Excel
Advance MS ExcelAdvance MS Excel
Advance MS Excel
acute23
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
Creating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using VbaCreating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using Vba
Chester Tugwell
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
Raghu nath
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 
Access tips access and sql part 2 putting vba and sql together
Access tips  access and sql part 2  putting vba and sql togetherAccess tips  access and sql part 2  putting vba and sql together
Access tips access and sql part 2 putting vba and sql together
quest2900
 

Similar to Intro to Excel VBA Programming (20)

200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
DannySingh23
 
Intro to Scala
 Intro to Scala Intro to Scala
Intro to Scala
manaswinimysore
 
Java Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer ScienceJava Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer Science
AnezkaJaved
 
Financial modeling sameh aljabli lecture 6
Financial modeling   sameh aljabli   lecture 6Financial modeling   sameh aljabli   lecture 6
Financial modeling sameh aljabli lecture 6
Sameh Algabli
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Unit 3-Javascript.pptx
Unit 3-Javascript.pptxUnit 3-Javascript.pptx
Unit 3-Javascript.pptx
AmanJha533833
 
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptxChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
bhuvanalakshmik2
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
NUST Stuff
 
Notes5
Notes5Notes5
Notes5
hccit
 
C functions
C functionsC functions
C functions
University of Potsdam
 
Improved VBA support
Improved VBA supportImproved VBA support
Improved VBA support
Alexandro Colorado
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
Abhishek Kesharwani
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
Brunel University
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
srikanthbkm
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
Ashish Chamoli
 
Advanced VLSI PPT 21EC71 MODULE 4.......
Advanced VLSI PPT 21EC71 MODULE 4.......Advanced VLSI PPT 21EC71 MODULE 4.......
Advanced VLSI PPT 21EC71 MODULE 4.......
BobanMathews2
 
Introduction to scientific computing with matlab.pptx
Introduction to scientific computing with matlab.pptxIntroduction to scientific computing with matlab.pptx
Introduction to scientific computing with matlab.pptx
CristianFloresMaldon
 
functions _
functions                                 _functions                                 _
functions _
SwatiHans10
 
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
DannySingh23
 
Java Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer ScienceJava Basic Elements Lecture on Computer Science
Java Basic Elements Lecture on Computer Science
AnezkaJaved
 
Financial modeling sameh aljabli lecture 6
Financial modeling   sameh aljabli   lecture 6Financial modeling   sameh aljabli   lecture 6
Financial modeling sameh aljabli lecture 6
Sameh Algabli
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Unit 3-Javascript.pptx
Unit 3-Javascript.pptxUnit 3-Javascript.pptx
Unit 3-Javascript.pptx
AmanJha533833
 
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptxChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
ChapterTwoandThreefnfgncvdjhgjshgjdlahgjlhglj.pptx
berihun18
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
NUST Stuff
 
Notes5
Notes5Notes5
Notes5
hccit
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
srikanthbkm
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
Ashish Chamoli
 
Advanced VLSI PPT 21EC71 MODULE 4.......
Advanced VLSI PPT 21EC71 MODULE 4.......Advanced VLSI PPT 21EC71 MODULE 4.......
Advanced VLSI PPT 21EC71 MODULE 4.......
BobanMathews2
 
Introduction to scientific computing with matlab.pptx
Introduction to scientific computing with matlab.pptxIntroduction to scientific computing with matlab.pptx
Introduction to scientific computing with matlab.pptx
CristianFloresMaldon
 
Ad

Recently uploaded (20)

E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
MICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdfMICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdf
DHARMENDRA SAHU
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
INQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptxINQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptx
SujatyaRoy
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
MICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdfMICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdf
DHARMENDRA SAHU
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
INQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptxINQUISITORS School Quiz Prelims 2025.pptx
INQUISITORS School Quiz Prelims 2025.pptx
SujatyaRoy
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
Ad

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 ?
  翻译: