SlideShare a Scribd company logo
1 of 11
Excel Macros Level 1 Functions and Subroutines
ByRef SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByRefiAs Integer) i = i + 1 End Sub M. Campbell - 2010 2 p. 73 This displays 6 as x had 1 added to it by AddOne
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 3 p. 73
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 4 p. 73 Initializes x to 5
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 5 p. 73 Displays 5
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 6 p. 73 Calls AddOne and sends value of x (in this case 5)
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 7 p. 73 AddOne is sent the value of x only, so i is set to 5
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 8 p. 73 1 is added to i to get 6 However, ProcedureA cannot see i
ByVal SubProcedureA() 	x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 9 p. 73 This displays 5 as x was not changed by AddOne
p. 75 ByRef ByVal Pass By Reference Allows the argument to be changed Takes less memory and time If not specified, VBA defaults to ByRef Pass By Value Prevents the argument from being changed Takes more memory and time 4/29/2010 M. Campbell - 2010 10
Exiting a Procedure To exit a function early: Exit Function To exit a subroutine early: Exit Sub 4/29/2010 M. Campbell - 2010 11 p. 76

More Related Content

What's hot

Expanding Exponent Quotients
Expanding Exponent QuotientsExpanding Exponent Quotients
Expanding Exponent Quotients
Passy World
 
2.7 Piecewise Functions
2.7 Piecewise Functions2.7 Piecewise Functions
2.7 Piecewise Functions
hisema01
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 

What's hot (18)

Mi primer map reduce
Mi primer map reduceMi primer map reduce
Mi primer map reduce
 
Mi primer map reduce
Mi primer map reduceMi primer map reduce
Mi primer map reduce
 
Parent Function Project
Parent Function ProjectParent Function Project
Parent Function Project
 
Why Hymans Use F#
Why Hymans Use F#Why Hymans Use F#
Why Hymans Use F#
 
Advanced python concepts
Advanced python conceptsAdvanced python concepts
Advanced python concepts
 
Expanding Exponent Quotients
Expanding Exponent QuotientsExpanding Exponent Quotients
Expanding Exponent Quotients
 
R - binomial distribution
R - binomial distributionR - binomial distribution
R - binomial distribution
 
2.7 Piecewise Functions
2.7 Piecewise Functions2.7 Piecewise Functions
2.7 Piecewise Functions
 
Perlで任意精度計算
Perlで任意精度計算Perlで任意精度計算
Perlで任意精度計算
 
Hw1 sol
Hw1 solHw1 sol
Hw1 sol
 
Derive Exponential Derivative Rule
Derive Exponential Derivative RuleDerive Exponential Derivative Rule
Derive Exponential Derivative Rule
 
Sign Sign 2
Sign Sign 2Sign Sign 2
Sign Sign 2
 
Scilab - Piecewise Functions
Scilab - Piecewise FunctionsScilab - Piecewise Functions
Scilab - Piecewise Functions
 
Regex, Python & Twitter
Regex, Python & TwitterRegex, Python & Twitter
Regex, Python & Twitter
 
Mysql count
Mysql countMysql count
Mysql count
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 

Viewers also liked

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
lotlot
 

Viewers also liked (14)

Chapter 3 Excel Macros
Chapter 3 Excel MacrosChapter 3 Excel Macros
Chapter 3 Excel Macros
 
Unit 6: Functions and Subroutines
Unit 6: Functions and SubroutinesUnit 6: Functions and Subroutines
Unit 6: Functions and Subroutines
 
Unit 7: Built-In Functions
Unit 7: Built-In FunctionsUnit 7: Built-In Functions
Unit 7: Built-In Functions
 
Chapter 2: Preliminaries
Chapter 2: PreliminariesChapter 2: Preliminaries
Chapter 2: Preliminaries
 
Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
Vba Excel Level 2
Vba Excel Level 2Vba Excel Level 2
Vba Excel Level 2
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
 
Flowchart pseudocode-examples
Flowchart pseudocode-examplesFlowchart pseudocode-examples
Flowchart pseudocode-examples
 
Tableau Server Basics
Tableau Server BasicsTableau Server Basics
Tableau Server Basics
 
Tableau Drive, A new methodology for scaling your analytic culture
Tableau Drive, A new methodology for scaling your analytic cultureTableau Drive, A new methodology for scaling your analytic culture
Tableau Drive, A new methodology for scaling your analytic culture
 
Tableau Software - Business Analytics and Data Visualization
Tableau Software - Business Analytics and Data VisualizationTableau Software - Business Analytics and Data Visualization
Tableau Software - Business Analytics and Data Visualization
 
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
Learning Tableau -  Data, Graphs, Filters, Dashboards and Advanced featuresLearning Tableau -  Data, Graphs, Filters, Dashboards and Advanced features
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
 

Similar to Unit 6: Functions and Subroutines - Part 2/2

Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
 

Similar to Unit 6: Functions and Subroutines - Part 2/2 (20)

Kajal Gaharwal , BCA Third Year
Kajal Gaharwal , BCA Third YearKajal Gaharwal , BCA Third Year
Kajal Gaharwal , BCA Third Year
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
 
Pooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearPooja Sharma , BCA Third Year
Pooja Sharma , BCA Third Year
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Aplikom11 matlab or
Aplikom11 matlab orAplikom11 matlab or
Aplikom11 matlab or
 
The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194The Ring programming language version 1.5.3 book - Part 188 of 194
The Ring programming language version 1.5.3 book - Part 188 of 194
 
Python Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionPython Puzzlers - 2016 Edition
Python Puzzlers - 2016 Edition
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
Opt simple single_000
Opt simple single_000Opt simple single_000
Opt simple single_000
 
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.ppt
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
The Ring programming language version 1.5.3 book - Part 27 of 184
The Ring programming language version 1.5.3 book - Part 27 of 184The Ring programming language version 1.5.3 book - Part 27 of 184
The Ring programming language version 1.5.3 book - Part 27 of 184
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 

More from Matthew Campbell, OCT

More from Matthew Campbell, OCT (6)

Cleaning The Part: Reclaim your Logging
Cleaning The Part: Reclaim your LoggingCleaning The Part: Reclaim your Logging
Cleaning The Part: Reclaim your Logging
 
Building Bridges: A DevOps Story
Building Bridges:  A DevOps StoryBuilding Bridges:  A DevOps Story
Building Bridges: A DevOps Story
 
Happy Teams Make Better Code
Happy Teams Make Better CodeHappy Teams Make Better Code
Happy Teams Make Better Code
 
Real World Retrospectives
Real World RetrospectivesReal World Retrospectives
Real World Retrospectives
 
Unit 8: Control Statements
Unit 8: Control StatementsUnit 8: Control Statements
Unit 8: Control Statements
 
Unit 5: Variables
Unit 5: VariablesUnit 5: Variables
Unit 5: Variables
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

Unit 6: Functions and Subroutines - Part 2/2

  • 1. Excel Macros Level 1 Functions and Subroutines
  • 2. ByRef SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByRefiAs Integer) i = i + 1 End Sub M. Campbell - 2010 2 p. 73 This displays 6 as x had 1 added to it by AddOne
  • 3. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 3 p. 73
  • 4. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 4 p. 73 Initializes x to 5
  • 5. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 5 p. 73 Displays 5
  • 6. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 6 p. 73 Calls AddOne and sends value of x (in this case 5)
  • 7. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 7 p. 73 AddOne is sent the value of x only, so i is set to 5
  • 8. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 8 p. 73 1 is added to i to get 6 However, ProcedureA cannot see i
  • 9. ByVal SubProcedureA() x = 5 MsgBox x CallAddOne(x) MsgBox x End Sub SubAddOne(ByValiAs Integer) i = i + 1 End Sub M. Campbell - 2010 9 p. 73 This displays 5 as x was not changed by AddOne
  • 10. p. 75 ByRef ByVal Pass By Reference Allows the argument to be changed Takes less memory and time If not specified, VBA defaults to ByRef Pass By Value Prevents the argument from being changed Takes more memory and time 4/29/2010 M. Campbell - 2010 10
  • 11. Exiting a Procedure To exit a function early: Exit Function To exit a subroutine early: Exit Sub 4/29/2010 M. Campbell - 2010 11 p. 76