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

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 1Er. Nawaraj Bhandari
 
Урок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖД
Урок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖДУрок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖД
Урок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖДNikolay Shaygorodskiy
 
поняття мови програмування
поняття мови програмуванняпоняття мови програмування
поняття мови програмуванняТатьяна Ляш
 
20 Unique Uses of Excel Spreadsheets
20 Unique Uses of Excel Spreadsheets20 Unique Uses of Excel Spreadsheets
20 Unique Uses of Excel SpreadsheetsNick Weisenberger
 
Entering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 TutorialEntering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 TutorialSpreadsheetTrainer
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosNick Weisenberger
 
ドメイン駆動設計 複雑さに立ち向かう
ドメイン駆動設計 複雑さに立ち向かうドメイン駆動設計 複雑さに立ち向かう
ドメイン駆動設計 複雑さに立ち向かう増田 亨
 
excel charts and graphs.ppt
excel charts and graphs.pptexcel charts and graphs.ppt
excel charts and graphs.pptChemOyasan1
 
Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...
Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...
Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...VsimPPT
 

Tendances (20)

Vba
Vba Vba
Vba
 
Learn Excel Macro
Learn Excel Macro  Learn Excel Macro
Learn Excel Macro
 
An introduction to vba and macros
An introduction to vba and macrosAn introduction to vba and macros
An introduction to vba and macros
 
MACROS excel
MACROS excelMACROS excel
MACROS excel
 
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
 
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
 
Урок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖД
Урок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖДУрок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖД
Урок №7. Практична робота №2. «Побудова інформаційних моделей» Інструктаж з БЖД
 
Flow chart
Flow chartFlow chart
Flow chart
 
Web Intents入門
Web Intents入門Web Intents入門
Web Intents入門
 
Microsoft visual basic 6
Microsoft visual basic 6Microsoft visual basic 6
Microsoft visual basic 6
 
поняття мови програмування
поняття мови програмуванняпоняття мови програмування
поняття мови програмування
 
20 Unique Uses of Excel Spreadsheets
20 Unique Uses of Excel Spreadsheets20 Unique Uses of Excel Spreadsheets
20 Unique Uses of Excel Spreadsheets
 
Paint
PaintPaint
Paint
 
Entering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 TutorialEntering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 Tutorial
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
 
середовище Lazarus
середовище Lazarusсередовище Lazarus
середовище Lazarus
 
ドメイン駆動設計 複雑さに立ち向かう
ドメイン駆動設計 複雑さに立ち向かうドメイン駆動設計 複雑さに立ち向かう
ドメイン駆動設計 複雑さに立ち向かう
 
excel charts and graphs.ppt
excel charts and graphs.pptexcel charts and graphs.ppt
excel charts and graphs.ppt
 
Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...
Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...
Урок 14 для 6 класу - Об'єкти презентації та засоби керування її демонстраціє...
 

En vedette

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 (13)

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

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
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
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
 

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

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
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.pptxJisc
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
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).pptxmarlenawright1
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
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.pptxDr. Ravikiran H M Gowda
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 

Dernier (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.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
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
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
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).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