SlideShare une entreprise Scribd logo
1  sur  14
Excel VBA Programming 3rd
         Session




AmeetZ Academy - An Easy Learning Source
Procedures
   Let us refresh our knowledge on Procedures which
   we learnt in Last session.
   A procedure is an assignment we give to VBScript to
   perform or to complete, the normal flow of the
   program/application. There are two kinds of
   procedures in VBScript:
   A sub procedure and a function. The difference
   between these two is their execution and Coding
   ( Programming) based on your goal.


AmeetZ Academy - An Easy Learning Source
VBA Procedures – Sub and Function
   Function is simply that a function can return a value
   to the procedure that called it. That procedure can
   be another Function, a Sub or even to a worksheet
   cell. When it is done using a worksheet formula, the
   Function is known as a User Defined Function, or
   UDF. Potentially all Functions are UDFs.
    Sub procedures are just like Functions, except that
   they do not return a value in the same way that a
   Function does. They can accept arguments, or not,
   just like a Function does.
AmeetZ Academy - An Easy Learning Source
VBA Procedures – Examples
• Sub Procedures
  A sub procedure is a section of code that carries an assignment but doesn't
  give back a result. To create a sub procedure, start the section of code with
  the Sub keyword followed by a name for the sub procedure. To differentiate
  the name of the sub procedure with any other regular name, it must be
  followed by an opening and closing parentheses.
   The section of the sub procedure code closes with End Sub as follows:

   Sub Macro1()
   '
   ‘ Macro1 Macro
       ActiveCell.FormulaR1C1 = "123"
       Range("A2").Select
   End Sub



AmeetZ Academy - An Easy Learning Source
VBA Procedures – Examples contd..
    • Creating a Function
      A function is an assignment that a piece of code can take care for
      the functionality of a database. The main difference between a sub
      procedure and a function procedure is that a function can return a
      value.

       A function is created like a sub procedure with a few more rules.
       The creation of function starts with the Function keyword and
       closes with End Function. Here is an example:

       Function FindFullName()

       End Function


AmeetZ Academy - An Easy Learning Source
PROCEDURES: PUBLIC OR PRIVATE

        By default all procedures are “Public”. That is
       to say that they can pretty much be used from
       anywhere in the project.
       For Sub procedures, it also means that they
       show up in the Tools | Macro | Macros list as
       available to be run through that interface ;and
       For Functions, public functions can be used as
       UDFs.

AmeetZ Academy - An Easy Learning Source
• But sometimes we don’t want the user to have
      access to a procedure, or don’t want other
      modules to be able to use a procedure in another
      module.
    • For those times, we can make a procedure only
      accessible from within the code module that it
      exists in by preceding its declaration with the
      word Private.
    • We , here, notice that all of the Workbook and
      Worksheet built-in event procedures are declared
      as Private. Subs that are declared as Private do
      not show up in the Tools | Macro | Macros list,
      and private functions are not available for use as
      UDFs.

AmeetZ Academy - An Easy Learning Source
Variables and Data Types
•    A variable is simply a named storage location in your computer’s memory.
•    You have lots of flexibility in naming your variables, so make the variable
•    names as descriptive as possible. You assign a value to a variable using
•    the equal sign operator. (More about this later in the “Using Assignment
•    Statements” section.)
•    The name of a variable:
    Must begin with a letter
    Cannot have a period (remember that we use the period to set a property; in
     other words the period is an operator)
    Can have up to 255 characters. Please, just because it is allowed, don't use
     255 characters.
    Must be unique inside of the procedure or the module it is used in (we will
     learn what a module is)
    Once a variable has a name, you can use it as you see fit.


AmeetZ Academy - An Easy Learning Source
• Why we use variables
   • Excel will still allow us to run our code without using
     variables, it is not a must! But having said this it is
     very bad programming to not use variables. You could
     quite easily just assign a value, string or whatever
     each time you need it, but it would mean:
      1) Your code would become hard to follow (even for
      yourself)
      2) Excel would constantly need to look for the value
      elsewhere.
      3) Editing your code would become awkward.


AmeetZ Academy - An Easy Learning Source
Example of Variable




        Code without Declaring Variable                 Code with Declaring Variable

   From the above screens, you can see Range(“A1:A6”) is been declared as “ameetzz” to
   have consistent code.

AmeetZ Academy - An Easy Learning Source
•   Variables can be declared as any one of the following data types:

    Byte data type

    A data type used to hold positive integer numbers ranging from 0 to 255. Byte variables are stored as
    single, unsigned 8-bit (1-byte) numbers.

    Boolean data type

    A data type with only two possible values, True (-1) or False (0). Boolean variables are stored as 16-bit
    (2-byte) numbers.

    Integer data type

    A data type that holds integer variables stored as 2-byte whole numbers in the range -32,768 to 32,767.
    The Integer data type is also used to represent enumerated values. The percent sign (%) type-
    declaration character represents an Integer in Visual Basic.

    Long data type

    A 4-byte integer ranging in value from -2,147,483,648 to 2,147,483,647. The ampersand (&) type-
    declaration character represents a Long in Visual Basic.


AmeetZ Academy - An Easy Learning Source
Currency data type
      A data type with a range of -922,337,203,685,477.5808 to
      922,337,203,685,477.5807. Use this data type for calculations
      involving money and for fixed-point calculations where accuracy is
      particularly important. The at sign (@) type-declaration character
      represents Currency in Visual Basic.
      Single data type
      A data type that stores single-precision floating-point variables as 32-
      bit (2-byte) floating-point numbers, ranging in value from -
      3.402823E38 to -1.401298E-45 for negative values, and 1.401298E-
      45 to 3.402823E38 for positive values. The exclamation point (!)
      type-declaration character represents a Single in Visual Basic.
      Double data type
      A data type that holds double-precision floating-point numbers as
      64-bit numbers in the range -1.79769313486232E308 to -
      4.94065645841247E-324 for negative values; 4.94065645841247E-
      324 to 1.79769313486232E308 for positive values. The number sign
      (#) type-declaration character represents the Double in Visual Basic.


AmeetZ Academy - An Easy Learning Source
Date data type
   A data type used to store dates and times as a real number. Date variables are
   stored as 64-bit (8-byte) numbers. The value to the left of the decimal represents a
   date, and the value to the right of the decimal represents a time.
   String data type
   A data type consisting of a sequence of contiguous characters that represent the
   characters themselves rather than their numeric values. A String can include
   letters, numbers, spaces, and punctuation. The String data type can store fixed-
   length strings ranging in length from 0 to approximately 63K characters and
   dynamic strings ranging in length from 0 to approximately 2 billion characters. The
   dollar sign ($) type-declaration character represents a String in Visual Basic.
   Object data type
   A data type that represents any Object reference. Object variables are stored as 32-
   bit (4-byte) addresses that refer to objects. Variant data type A special data type
   that can contain numeric, string, or date data as well as the special values Empty
   and Null. The Variant data type has a numeric storage size of 16 bytes and can
   contain data up to the range of a Decimal, or a character storage size of 22 bytes
   (plus string length), and can store any character text. The VarType function defines
   how the data in a Variant is treated. All variables become Variant data types if not
   explicitly declared as some other data type.

AmeetZ Academy - An Easy Learning Source
Next Class we will discuss , all Data Types with
       Examples

       Now we slowly are entering into coding hence
       be prompt to the classes




AmeetZ Academy - An Easy Learning Source

Contenu connexe

Tendances (20)

Introduction to Excel VBA/Macros
Introduction to Excel VBA/MacrosIntroduction to Excel VBA/Macros
Introduction to Excel VBA/Macros
 
An introduction to vba and macros
An introduction to vba and macrosAn introduction to vba and macros
An introduction to vba and macros
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
 
VBA - Macro For Ms.Excel
VBA - Macro For Ms.ExcelVBA - Macro For Ms.Excel
VBA - Macro For Ms.Excel
 
Microsoft Excel - Macros
Microsoft Excel - MacrosMicrosoft Excel - Macros
Microsoft Excel - Macros
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
Vba
Vba Vba
Vba
 
Using macros in microsoft excel part 1
Using macros in microsoft excel   part 1Using macros in microsoft excel   part 1
Using macros in microsoft excel part 1
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
Add or Remove Password Protection in Excel 2016
Add or Remove Password Protection in Excel 2016Add or Remove Password Protection in Excel 2016
Add or Remove Password Protection in Excel 2016
 
Visual basic
Visual basicVisual basic
Visual basic
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
Visual Basic menu
Visual Basic menuVisual Basic menu
Visual Basic menu
 
Vb6.0 Introduction
Vb6.0 IntroductionVb6.0 Introduction
Vb6.0 Introduction
 
Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6Introduction to programming using Visual Basic 6
Introduction to programming using Visual Basic 6
 
Grade 5 Computer
Grade 5 ComputerGrade 5 Computer
Grade 5 Computer
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
 
Intro to Microsoft Excel 2007
Intro to Microsoft Excel 2007Intro to Microsoft Excel 2007
Intro to Microsoft Excel 2007
 
Entering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 TutorialEntering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 Tutorial
 

En vedette

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 1Vijay Perepa
 
Up and running with VBA in Excel Certificate of Completion
Up and running with VBA in Excel Certificate of CompletionUp and running with VBA in Excel Certificate of Completion
Up and running with VBA in Excel Certificate of CompletionDamien Asseya
 
Introduction To Predictive Analytics Part I
Introduction To Predictive Analytics   Part IIntroduction To Predictive Analytics   Part I
Introduction To Predictive Analytics Part Ijayroy
 
Google Analytics
Google AnalyticsGoogle Analytics
Google AnalyticsRohan Dighe
 
Predictive Analytics - An Overview
Predictive Analytics - An OverviewPredictive Analytics - An Overview
Predictive Analytics - An OverviewMachinePulse
 
Google Analytics 101 for Business - How to Get Started With Google Analytics
Google Analytics 101 for Business - How to Get Started With Google AnalyticsGoogle Analytics 101 for Business - How to Get Started With Google Analytics
Google Analytics 101 for Business - How to Get Started With Google AnalyticsJeff Sauer
 
An introduction to Google Analytics
An introduction to Google AnalyticsAn introduction to Google Analytics
An introduction to Google AnalyticsJoris Roebben
 
Lean Analytics Cycle
Lean Analytics CycleLean Analytics Cycle
Lean Analytics CycleHiten Shah
 
MS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMridul Bansal
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosExcel
 

En vedette (14)

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
 
Google Analytics Overview
Google Analytics OverviewGoogle Analytics Overview
Google Analytics Overview
 
Up and running with VBA in Excel Certificate of Completion
Up and running with VBA in Excel Certificate of CompletionUp and running with VBA in Excel Certificate of Completion
Up and running with VBA in Excel Certificate of Completion
 
Vba Class Level 1
Vba Class Level 1Vba Class Level 1
Vba Class Level 1
 
Introduction To Predictive Analytics Part I
Introduction To Predictive Analytics   Part IIntroduction To Predictive Analytics   Part I
Introduction To Predictive Analytics Part I
 
Google Analytics
Google AnalyticsGoogle Analytics
Google Analytics
 
Predictive Analytics - An Overview
Predictive Analytics - An OverviewPredictive Analytics - An Overview
Predictive Analytics - An Overview
 
Excel Macro Magic
Excel Macro MagicExcel Macro Magic
Excel Macro Magic
 
Excel ch10
Excel ch10Excel ch10
Excel ch10
 
Google Analytics 101 for Business - How to Get Started With Google Analytics
Google Analytics 101 for Business - How to Get Started With Google AnalyticsGoogle Analytics 101 for Business - How to Get Started With Google Analytics
Google Analytics 101 for Business - How to Get Started With Google Analytics
 
An introduction to Google Analytics
An introduction to Google AnalyticsAn introduction to Google Analytics
An introduction to Google Analytics
 
Lean Analytics Cycle
Lean Analytics CycleLean Analytics Cycle
Lean Analytics Cycle
 
MS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATION
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 Macros
 

Similaire à E learning excel vba programming lesson 3

Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingAbha Damani
 
Java platform
Java platformJava platform
Java platformVisithan
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxssusere336f4
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGERathnaM16
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosEmmett Ross
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsShanmuganathan C
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application Raghu nath
 
Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Subhash Patel
 

Similaire à E learning excel vba programming lesson 3 (20)

Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
I x scripting
I x scriptingI x scripting
I x scripting
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
C#
C#C#
C#
 
Java platform
Java platformJava platform
Java platform
 
C question
C questionC question
C question
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
 
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGEINTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
INTRODUCTION TO CODING-CLASS VI LEVEL-DESCRIPTION ABOUT SYNTAX LANGUAGE
 
VB.net
VB.netVB.net
VB.net
 
Getting started with CATIA V5 Macros
Getting started with CATIA V5 MacrosGetting started with CATIA V5 Macros
Getting started with CATIA V5 Macros
 
PRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdfPRELIM-Lesson-2.pdf
PRELIM-Lesson-2.pdf
 
Pc module1
Pc module1Pc module1
Pc module1
 
OODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objectsOODP Unit 1 OOPs classes and objects
OODP Unit 1 OOPs classes and objects
 
73d32 session1 c++
73d32 session1 c++73d32 session1 c++
73d32 session1 c++
 
VBA
VBAVBA
VBA
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
 
Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0Mule soft meetup_charlotte_4__draft_v2.0
Mule soft meetup_charlotte_4__draft_v2.0
 

Plus de Vijay Perepa

Access essential training framework
Access essential training   frameworkAccess essential training   framework
Access essential training frameworkVijay Perepa
 
Add picture to comment
Add picture to commentAdd picture to comment
Add picture to commentVijay Perepa
 
Excel short cut series function keys
Excel short cut series   function keysExcel short cut series   function keys
Excel short cut series function keysVijay Perepa
 
PowerPoint Info-Graphics
PowerPoint Info-GraphicsPowerPoint Info-Graphics
PowerPoint Info-GraphicsVijay Perepa
 
Types of charts in Excel and How to use them
Types of charts in Excel and How to use themTypes of charts in Excel and How to use them
Types of charts in Excel and How to use themVijay Perepa
 
Pivot table essential learning 1
Pivot table   essential learning 1Pivot table   essential learning 1
Pivot table essential learning 1Vijay Perepa
 
Pivot table essential learning 2
Pivot table   essential learning 2Pivot table   essential learning 2
Pivot table essential learning 2Vijay Perepa
 
Modeling in microsoft excel
Modeling in microsoft excelModeling in microsoft excel
Modeling in microsoft excelVijay Perepa
 
Understanding excel’s error values
Understanding excel’s error valuesUnderstanding excel’s error values
Understanding excel’s error valuesVijay Perepa
 
Excel training commands not in ribbon
Excel training   commands not in ribbonExcel training   commands not in ribbon
Excel training commands not in ribbonVijay Perepa
 
E learning excel vba programming lesson 5
E learning excel vba programming  lesson 5E learning excel vba programming  lesson 5
E learning excel vba programming lesson 5Vijay Perepa
 
E learning excel vba programming lesson 4
E learning excel vba programming  lesson 4E learning excel vba programming  lesson 4
E learning excel vba programming lesson 4Vijay Perepa
 
Power point short cut keys
Power point short cut keysPower point short cut keys
Power point short cut keysVijay Perepa
 
Understanding excel’s error values
Understanding excel’s error valuesUnderstanding excel’s error values
Understanding excel’s error valuesVijay Perepa
 
Excel information formulae par ii ameet z academy
Excel information formulae par ii  ameet z academyExcel information formulae par ii  ameet z academy
Excel information formulae par ii ameet z academyVijay Perepa
 
Excel information formulae ameet z academy
Excel information formulae   ameet z academyExcel information formulae   ameet z academy
Excel information formulae ameet z academyVijay Perepa
 
Excel text formulae ameet z academy
Excel text formulae   ameet z academyExcel text formulae   ameet z academy
Excel text formulae ameet z academyVijay Perepa
 
E-Learning from Ameetz (ISERROR formula)
E-Learning from Ameetz (ISERROR formula)E-Learning from Ameetz (ISERROR formula)
E-Learning from Ameetz (ISERROR formula)Vijay Perepa
 
E learning excel short cut keys
E learning excel short cut keysE learning excel short cut keys
E learning excel short cut keysVijay Perepa
 

Plus de Vijay Perepa (20)

Access essential training framework
Access essential training   frameworkAccess essential training   framework
Access essential training framework
 
Add picture to comment
Add picture to commentAdd picture to comment
Add picture to comment
 
Excel short cut series function keys
Excel short cut series   function keysExcel short cut series   function keys
Excel short cut series function keys
 
PowerPoint Info-Graphics
PowerPoint Info-GraphicsPowerPoint Info-Graphics
PowerPoint Info-Graphics
 
Types of charts in Excel and How to use them
Types of charts in Excel and How to use themTypes of charts in Excel and How to use them
Types of charts in Excel and How to use them
 
Pivot table essential learning 1
Pivot table   essential learning 1Pivot table   essential learning 1
Pivot table essential learning 1
 
Pivot table essential learning 2
Pivot table   essential learning 2Pivot table   essential learning 2
Pivot table essential learning 2
 
Modeling in microsoft excel
Modeling in microsoft excelModeling in microsoft excel
Modeling in microsoft excel
 
Understanding excel’s error values
Understanding excel’s error valuesUnderstanding excel’s error values
Understanding excel’s error values
 
Excel training commands not in ribbon
Excel training   commands not in ribbonExcel training   commands not in ribbon
Excel training commands not in ribbon
 
E learning excel vba programming lesson 5
E learning excel vba programming  lesson 5E learning excel vba programming  lesson 5
E learning excel vba programming lesson 5
 
E learning excel vba programming lesson 4
E learning excel vba programming  lesson 4E learning excel vba programming  lesson 4
E learning excel vba programming lesson 4
 
Pivot table
Pivot tablePivot table
Pivot table
 
Power point short cut keys
Power point short cut keysPower point short cut keys
Power point short cut keys
 
Understanding excel’s error values
Understanding excel’s error valuesUnderstanding excel’s error values
Understanding excel’s error values
 
Excel information formulae par ii ameet z academy
Excel information formulae par ii  ameet z academyExcel information formulae par ii  ameet z academy
Excel information formulae par ii ameet z academy
 
Excel information formulae ameet z academy
Excel information formulae   ameet z academyExcel information formulae   ameet z academy
Excel information formulae ameet z academy
 
Excel text formulae ameet z academy
Excel text formulae   ameet z academyExcel text formulae   ameet z academy
Excel text formulae ameet z academy
 
E-Learning from Ameetz (ISERROR formula)
E-Learning from Ameetz (ISERROR formula)E-Learning from Ameetz (ISERROR formula)
E-Learning from Ameetz (ISERROR formula)
 
E learning excel short cut keys
E learning excel short cut keysE learning excel short cut keys
E learning excel short cut keys
 

Dernier

Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 

Dernier (20)

Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 

E learning excel vba programming lesson 3

  • 1. Excel VBA Programming 3rd Session AmeetZ Academy - An Easy Learning Source
  • 2. Procedures Let us refresh our knowledge on Procedures which we learnt in Last session. A procedure is an assignment we give to VBScript to perform or to complete, the normal flow of the program/application. There are two kinds of procedures in VBScript: A sub procedure and a function. The difference between these two is their execution and Coding ( Programming) based on your goal. AmeetZ Academy - An Easy Learning Source
  • 3. VBA Procedures – Sub and Function Function is simply that a function can return a value to the procedure that called it. That procedure can be another Function, a Sub or even to a worksheet cell. When it is done using a worksheet formula, the Function is known as a User Defined Function, or UDF. Potentially all Functions are UDFs. Sub procedures are just like Functions, except that they do not return a value in the same way that a Function does. They can accept arguments, or not, just like a Function does. AmeetZ Academy - An Easy Learning Source
  • 4. VBA Procedures – Examples • Sub Procedures A sub procedure is a section of code that carries an assignment but doesn't give back a result. To create a sub procedure, start the section of code with the Sub keyword followed by a name for the sub procedure. To differentiate the name of the sub procedure with any other regular name, it must be followed by an opening and closing parentheses. The section of the sub procedure code closes with End Sub as follows: Sub Macro1() ' ‘ Macro1 Macro ActiveCell.FormulaR1C1 = "123" Range("A2").Select End Sub AmeetZ Academy - An Easy Learning Source
  • 5. VBA Procedures – Examples contd.. • Creating a Function A function is an assignment that a piece of code can take care for the functionality of a database. The main difference between a sub procedure and a function procedure is that a function can return a value. A function is created like a sub procedure with a few more rules. The creation of function starts with the Function keyword and closes with End Function. Here is an example: Function FindFullName() End Function AmeetZ Academy - An Easy Learning Source
  • 6. PROCEDURES: PUBLIC OR PRIVATE By default all procedures are “Public”. That is to say that they can pretty much be used from anywhere in the project. For Sub procedures, it also means that they show up in the Tools | Macro | Macros list as available to be run through that interface ;and For Functions, public functions can be used as UDFs. AmeetZ Academy - An Easy Learning Source
  • 7. • But sometimes we don’t want the user to have access to a procedure, or don’t want other modules to be able to use a procedure in another module. • For those times, we can make a procedure only accessible from within the code module that it exists in by preceding its declaration with the word Private. • We , here, notice that all of the Workbook and Worksheet built-in event procedures are declared as Private. Subs that are declared as Private do not show up in the Tools | Macro | Macros list, and private functions are not available for use as UDFs. AmeetZ Academy - An Easy Learning Source
  • 8. Variables and Data Types • A variable is simply a named storage location in your computer’s memory. • You have lots of flexibility in naming your variables, so make the variable • names as descriptive as possible. You assign a value to a variable using • the equal sign operator. (More about this later in the “Using Assignment • Statements” section.) • The name of a variable: Must begin with a letter Cannot have a period (remember that we use the period to set a property; in other words the period is an operator) Can have up to 255 characters. Please, just because it is allowed, don't use 255 characters. Must be unique inside of the procedure or the module it is used in (we will learn what a module is) Once a variable has a name, you can use it as you see fit. AmeetZ Academy - An Easy Learning Source
  • 9. • Why we use variables • Excel will still allow us to run our code without using variables, it is not a must! But having said this it is very bad programming to not use variables. You could quite easily just assign a value, string or whatever each time you need it, but it would mean: 1) Your code would become hard to follow (even for yourself) 2) Excel would constantly need to look for the value elsewhere. 3) Editing your code would become awkward. AmeetZ Academy - An Easy Learning Source
  • 10. Example of Variable Code without Declaring Variable Code with Declaring Variable From the above screens, you can see Range(“A1:A6”) is been declared as “ameetzz” to have consistent code. AmeetZ Academy - An Easy Learning Source
  • 11. Variables can be declared as any one of the following data types: Byte data type A data type used to hold positive integer numbers ranging from 0 to 255. Byte variables are stored as single, unsigned 8-bit (1-byte) numbers. Boolean data type A data type with only two possible values, True (-1) or False (0). Boolean variables are stored as 16-bit (2-byte) numbers. Integer data type A data type that holds integer variables stored as 2-byte whole numbers in the range -32,768 to 32,767. The Integer data type is also used to represent enumerated values. The percent sign (%) type- declaration character represents an Integer in Visual Basic. Long data type A 4-byte integer ranging in value from -2,147,483,648 to 2,147,483,647. The ampersand (&) type- declaration character represents a Long in Visual Basic. AmeetZ Academy - An Easy Learning Source
  • 12. Currency data type A data type with a range of -922,337,203,685,477.5808 to 922,337,203,685,477.5807. Use this data type for calculations involving money and for fixed-point calculations where accuracy is particularly important. The at sign (@) type-declaration character represents Currency in Visual Basic. Single data type A data type that stores single-precision floating-point variables as 32- bit (2-byte) floating-point numbers, ranging in value from - 3.402823E38 to -1.401298E-45 for negative values, and 1.401298E- 45 to 3.402823E38 for positive values. The exclamation point (!) type-declaration character represents a Single in Visual Basic. Double data type A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486232E308 to - 4.94065645841247E-324 for negative values; 4.94065645841247E- 324 to 1.79769313486232E308 for positive values. The number sign (#) type-declaration character represents the Double in Visual Basic. AmeetZ Academy - An Easy Learning Source
  • 13. Date data type A data type used to store dates and times as a real number. Date variables are stored as 64-bit (8-byte) numbers. The value to the left of the decimal represents a date, and the value to the right of the decimal represents a time. String data type A data type consisting of a sequence of contiguous characters that represent the characters themselves rather than their numeric values. A String can include letters, numbers, spaces, and punctuation. The String data type can store fixed- length strings ranging in length from 0 to approximately 63K characters and dynamic strings ranging in length from 0 to approximately 2 billion characters. The dollar sign ($) type-declaration character represents a String in Visual Basic. Object data type A data type that represents any Object reference. Object variables are stored as 32- bit (4-byte) addresses that refer to objects. Variant data type A special data type that can contain numeric, string, or date data as well as the special values Empty and Null. The Variant data type has a numeric storage size of 16 bytes and can contain data up to the range of a Decimal, or a character storage size of 22 bytes (plus string length), and can store any character text. The VarType function defines how the data in a Variant is treated. All variables become Variant data types if not explicitly declared as some other data type. AmeetZ Academy - An Easy Learning Source
  • 14. Next Class we will discuss , all Data Types with Examples Now we slowly are entering into coding hence be prompt to the classes AmeetZ Academy - An Easy Learning Source