1. Introduction to
Excel VBA/Macros:
Some Examples on Logistics
and Supply Chain Management
Dr. Kang Mun Arturo Tan
Assistant Professor
Logistics and Supply Chain Management
Data Analytics
Yanbu University College
2. General Outline
A_Why does Excel VBA matter?
B_ What is VBA?
C_ How do we start with VBA?
D_ Recording some macros.
E_ Running the macros.
F_ Functions and Sub_Routines.
G_ The User Form.
slideNo3
Thanks
COVER
4. A_ Why does VBA Excel Matter
Excel is widely used across the world.
5. A_ Why does VBA Excel Matter
Excel is widely used across the world.
Many corporate data, both structured
and unstructured are in Excel.
6. A_ Why does VBA Excel Matter
Excel is widely used across the world.
Many corporate data, both structured
and unstructured are in Excel.
Processing of data residing in Excel
has become a routine work for many
professionals.
7. A_ Why does VBA Excel Matter
Excel is widely used across the world.
Many corporate data, both structured
and unstructured are in Excel.
Processing of data residing in Excel
has become a routine work for many
professionals.
Automating this work could be an added
advantage for the students who are
entering the workforce.
BackToTOC
8. B_ What is VBA
VBA stands for Visual Basic for
Application.
It is very similar to Visual Basic
in form and structure.
It works with Excel, Word, Access,
Powerpoint and Outlook.
9. Theory:
For Excel, it deals with Excel Object Model.
Object, intuitively, is like an XLNoid – a robot.
Method is a call to action.
Property is a data stored in that data basket, with
the XLNoid constantly checking, and deciding
if an action is needed.
35. F_ Functions and Sub Routines
Cell
To Fill Up a Cell with a Value
To Fill Up a Cell with a Formula
To Read a Cell’s Value
36. F_ Functions and Sub Routines
BegInvy + Receipts – Issuances
= EndInvy
As a function:
As a subprocedure:
Demo for
Coding
of
Sub proc
and
Functions
Tan_FA_Slide
37. F_ Functions and Sub Routines
EoQ = Sqrt (2 DS / H )
D = Demand for a Year
S = Cost for each Ordering
H = Holding Cost per Item per Year
Demo for Preparing
A report
BackToTOC
BackToF
Tan_FA_Slide
38. Fc1_ General Example
Option Explicit
Sub MyMacroGetMax()
Dim q As Variant
Dim x(100) As Integer
Dim i As Integer, nPtr As Integer
Dim Start As Integer, Last As Integer, Num As Integer
Dim AssumedHeaviest, Heaviest As Integer
' Defining the array
q = Array(7, 2, 3, 20, 15, 6, 35, 12, 9, 5, 18, 23, _
9, 16, 22, 10)
Demo for Straight Coding
Tan_FC_Slide
39. Fc2_ General Example
Start = LBound(q)
MsgBox "StartBoxNo is " & Start
Last = UBound(q)
MsgBox "LastBoxNo is " & Last
Num = Last - Start + 1
MsgBox "BoxCount is " & Num
' = = == = = = = = =
' transferring the content of container q to container x.
‘ container x is a temporary place for comparison.
' ========= = = = = =
For i = Start To Last
x(i) = q(i)
Next i
' = = = = = = = = = = =
40. Fc3_ General Example
' = =
' assume the first box to be the heaviest.
' = = =
AssumedHeaviest = x(Start) ‘// Start means the first box
' = = = =
For nPtr = Start + 1 To Last ‘// Start+1 means the second box
If x(nPtr) > AssumedHeaviest Then
AssumedHeaviest = x(nPtr)
End If
Next nPtr
Heaviest = AssumedHeaviest
MsgBox "Heaviest is " & Heaviest
End Sub
BackToTOC
BackToFc