SlideShare a Scribd company logo
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
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
A_ Why does Excel VBA Matter
A_ Why does VBA Excel Matter
Excel is widely used across the world.
A_ Why does VBA Excel Matter
Excel is widely used across the world.
Many corporate data, both structured
and unstructured are in Excel.
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.
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
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.
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.
Theory: Overall Structure
Application Project
Worksheets Modules User_Form
Macro Window
Buttons
Call Form
Read/Write Data
For Excel, it deals with Excel Object Model.
Application
Workbook
Worksheets
Range
Cell
BackToTOC
BackTo_B
C_ How do we start with Excel VBA
Check for Activation
Demo for Start Up
Tan_C_Slide
C_ How do we start with Excel VBA
C_ How do we start with Excel VBA
C_ How do we start with Excel VBA
C_ How do we start with Excel VBA
C_ How do we start with Excel VBA
BackToTOC
BackToC
D_ Recording some VBA Macros Show
Recording
Process
Tan_D_Slide
D_ Recording some VBA Macros
D_ Recording some VBA Macros
D_ Recording some VBA Macros
D_ Recording some VBA Macros
D_ Recording some VBA Macros
D_ Recording some VBA Macros
Overall code
D_ Recording some VBA Macros
R[ Up/Down CellDistance] C[Left/Right CellDistance]
Focusing on the formula:
“R[-4] C + R[-3] C - R[-2] C “
D_ Recording some VBA Macros
ActiveCell.Offset( Up/Down CellStep, Left/Right CellStep)
Relative Recording
D_ Recording some VBA Macros
Calling both MyMacro01 and MyMacro02
D_ Recording some VBA Macros
D_ Recording some VBA Macros
D_ Recording some VBA Macros
Clearing the area
BackToTOC
BackToD
E_ Running the macros
Alt+F8
Analyzing
the recorded
macros
Tan_E_Slide
E_ Running the macros
E_ Running the macros
E_ Running the macros
BackToTOC
BackToE
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
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
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
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
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
' = = = = = = = = = = =
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
G_ UserForm Example
Call Demo G
Tan_G_Slide
G_ UserForm Example
G_ UserForm Example
G_ UserForm Example
G_ UserForm Example
G_ UserForm Example
G_ UserForm Example
BackToTOC
BackToG
H_ Overall Structure
Application Project
Worksheets Modules User_Form
Macro Window
Buttons
Call Form
Read/Write Data
BackToTOC
Thank You!!!!!
BackToTOC

More Related Content

What's hot

MACROS excel
MACROS excelMACROS excel
MACROS excel
Zenobia Sukhia
 
VBA - Macro For Ms.Excel
VBA - Macro For Ms.ExcelVBA - Macro For Ms.Excel
VBA - Macro For Ms.Excel
C-Train Learning Point
 
Excel training
Excel  training Excel  training
Excel training
jaydip gupte
 
Excel Macro Magic
Excel Macro MagicExcel Macro Magic
Excel Macro Magic
Elaine Giles
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
ibinstitute0
 
Excel training
Excel trainingExcel training
Excel training
Alexandru Gologan
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
Vijay Perepa
 
03 Excel formulas and functions
03 Excel formulas and functions03 Excel formulas and functions
03 Excel formulas and functionsBuffalo Seminary
 
Microsoft excel
Microsoft excelMicrosoft excel
Microsoft excel14312
 
Teaching Excel
Teaching ExcelTeaching Excel
Teaching Excelsam ran
 
Microsoft Excel 101
Microsoft Excel 101Microsoft Excel 101
Microsoft Excel 101
Louis Honeyman
 
Microsoft Excel Tutorial
Microsoft Excel TutorialMicrosoft Excel Tutorial
Microsoft Excel Tutorial
Kristine Tiongco-Rimpa
 
Introduction to Microsoft Excel for beginners
Introduction to Microsoft Excel for beginnersIntroduction to Microsoft Excel for beginners
Introduction to Microsoft Excel for beginners
Blogger Mumma
 
Microsoft Excel - Macros
Microsoft Excel - MacrosMicrosoft Excel - Macros
Microsoft Excel - Macros
Eladio Jose Abquina
 
Charts in EXCEL
Charts in EXCELCharts in EXCEL
Charts in EXCEL
pkottke
 
Learn Excel Macro
Learn Excel Macro  Learn Excel Macro
Learn Excel Macro
AbhisheK Kumar Rajoria
 
An introduction to vba and macros
An introduction to vba and macrosAn introduction to vba and macros
An introduction to vba and macros
Er. Nawaraj Bhandari
 
excel charts and graphs.ppt
excel charts and graphs.pptexcel charts and graphs.ppt
excel charts and graphs.ppt
ChemOyasan1
 
Formulas and functions - By Amresh Tiwari
Formulas and functions - By Amresh TiwariFormulas and functions - By Amresh Tiwari
Formulas and functions - By Amresh Tiwari
Amresh Tiwari
 

What's hot (20)

MACROS excel
MACROS excelMACROS excel
MACROS excel
 
VBA - Macro For Ms.Excel
VBA - Macro For Ms.ExcelVBA - Macro For Ms.Excel
VBA - Macro For Ms.Excel
 
Excel training
Excel  training Excel  training
Excel training
 
Excel Macro Magic
Excel Macro MagicExcel Macro Magic
Excel Macro Magic
 
Advanced Excel ppt
Advanced Excel pptAdvanced Excel ppt
Advanced Excel ppt
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
Excel training
Excel trainingExcel training
Excel training
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
 
03 Excel formulas and functions
03 Excel formulas and functions03 Excel formulas and functions
03 Excel formulas and functions
 
Microsoft excel
Microsoft excelMicrosoft excel
Microsoft excel
 
Teaching Excel
Teaching ExcelTeaching Excel
Teaching Excel
 
Microsoft Excel 101
Microsoft Excel 101Microsoft Excel 101
Microsoft Excel 101
 
Microsoft Excel Tutorial
Microsoft Excel TutorialMicrosoft Excel Tutorial
Microsoft Excel Tutorial
 
Introduction to Microsoft Excel for beginners
Introduction to Microsoft Excel for beginnersIntroduction to Microsoft Excel for beginners
Introduction to Microsoft Excel for beginners
 
Microsoft Excel - Macros
Microsoft Excel - MacrosMicrosoft Excel - Macros
Microsoft Excel - Macros
 
Charts in EXCEL
Charts in EXCELCharts in EXCEL
Charts in EXCEL
 
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
 
excel charts and graphs.ppt
excel charts and graphs.pptexcel charts and graphs.ppt
excel charts and graphs.ppt
 
Formulas and functions - By Amresh Tiwari
Formulas and functions - By Amresh TiwariFormulas and functions - By Amresh Tiwari
Formulas and functions - By Amresh Tiwari
 

Similar to Introduction to Excel VBA/Macros

Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
smumbahelp
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
CHOOSE
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
AlbanLevy
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
ibinstitute0
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
Joselito Perez
 
Matopt
MatoptMatopt
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
RaajTech
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
Mard Geer
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
SourabhPal46
 
Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)
mehek4
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
Fwdays
 
2. data types, variables and operators
2. data types, variables and operators2. data types, variables and operators
2. data types, variables and operators
PhD Research Scholar
 
Vba and macro creation (using excel)
Vba and macro creation (using excel)Vba and macro creation (using excel)
Vba and macro creation (using excel)
Javier Morales Cauna
 
Access tips access and sql part 2 putting vba and sql together
Access tips  access and sql part 2  putting vba and sql togetherAccess tips  access and sql part 2  putting vba and sql together
Access tips access and sql part 2 putting vba and sql together
quest2900
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
DHRUYEN HADIYA
 

Similar to Introduction to Excel VBA/Macros (20)

Unit 3
Unit 3Unit 3
Unit 3
 
Bt0082, visual basic
Bt0082, visual basicBt0082, visual basic
Bt0082, visual basic
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
 
Matopt
MatoptMatopt
Matopt
 
70433 Dumps DB
70433 Dumps DB70433 Dumps DB
70433 Dumps DB
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
lec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.pptlec_4_data_structures_and_algorithm_analysis.ppt
lec_4_data_structures_and_algorithm_analysis.ppt
 
Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)
 
pm1
pm1pm1
pm1
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
2. data types, variables and operators
2. data types, variables and operators2. data types, variables and operators
2. data types, variables and operators
 
Vba and macro creation (using excel)
Vba and macro creation (using excel)Vba and macro creation (using excel)
Vba and macro creation (using excel)
 
Access tips access and sql part 2 putting vba and sql together
Access tips  access and sql part 2  putting vba and sql togetherAccess tips  access and sql part 2  putting vba and sql together
Access tips access and sql part 2 putting vba and sql together
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
 

More from arttan2001

Dax Power Pivot: Introductory Level
Dax Power Pivot: Introductory Level Dax Power Pivot: Introductory Level
Dax Power Pivot: Introductory Level
arttan2001
 
Uber210 slide share
Uber210 slide shareUber210 slide share
Uber210 slide share
arttan2001
 
Logistics Systems Design for the Yangtze River Delta Region
Logistics Systems Design for the Yangtze River Delta RegionLogistics Systems Design for the Yangtze River Delta Region
Logistics Systems Design for the Yangtze River Delta Region
arttan2001
 
Summarizing Siegel's Predictive Analytics
Summarizing Siegel's Predictive Analytics Summarizing Siegel's Predictive Analytics
Summarizing Siegel's Predictive Analytics
arttan2001
 
On Big Data
On Big DataOn Big Data
On Big Data
arttan2001
 
Linux for Education
Linux for EducationLinux for Education
Linux for Education
arttan2001
 
R and Rcmdr Statistical Software
R and Rcmdr Statistical SoftwareR and Rcmdr Statistical Software
R and Rcmdr Statistical Software
arttan2001
 

More from arttan2001 (7)

Dax Power Pivot: Introductory Level
Dax Power Pivot: Introductory Level Dax Power Pivot: Introductory Level
Dax Power Pivot: Introductory Level
 
Uber210 slide share
Uber210 slide shareUber210 slide share
Uber210 slide share
 
Logistics Systems Design for the Yangtze River Delta Region
Logistics Systems Design for the Yangtze River Delta RegionLogistics Systems Design for the Yangtze River Delta Region
Logistics Systems Design for the Yangtze River Delta Region
 
Summarizing Siegel's Predictive Analytics
Summarizing Siegel's Predictive Analytics Summarizing Siegel's Predictive Analytics
Summarizing Siegel's Predictive Analytics
 
On Big Data
On Big DataOn Big Data
On Big Data
 
Linux for Education
Linux for EducationLinux for Education
Linux for Education
 
R and Rcmdr Statistical Software
R and Rcmdr Statistical SoftwareR and Rcmdr Statistical Software
R and Rcmdr Statistical Software
 

Recently uploaded

Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
Oppotus
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
ewymefz
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
nscud
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
balafet
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 

Recently uploaded (20)

Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
Machine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptxMachine learning and optimization techniques for electrical drives.pptx
Machine learning and optimization techniques for electrical drives.pptx
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 

Introduction to Excel VBA/Macros

  • 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
  • 3. A_ Why does Excel VBA Matter
  • 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.
  • 10. Theory: Overall Structure Application Project Worksheets Modules User_Form Macro Window Buttons Call Form Read/Write Data
  • 11. For Excel, it deals with Excel Object Model. Application Workbook Worksheets Range Cell BackToTOC BackTo_B
  • 12. C_ How do we start with Excel VBA Check for Activation Demo for Start Up Tan_C_Slide
  • 13. C_ How do we start with Excel VBA
  • 14. C_ How do we start with Excel VBA
  • 15. C_ How do we start with Excel VBA
  • 16. C_ How do we start with Excel VBA
  • 17. C_ How do we start with Excel VBA BackToTOC BackToC
  • 18. D_ Recording some VBA Macros Show Recording Process Tan_D_Slide
  • 19. D_ Recording some VBA Macros
  • 20. D_ Recording some VBA Macros
  • 21. D_ Recording some VBA Macros
  • 22. D_ Recording some VBA Macros
  • 23. D_ Recording some VBA Macros
  • 24. D_ Recording some VBA Macros Overall code
  • 25. D_ Recording some VBA Macros R[ Up/Down CellDistance] C[Left/Right CellDistance] Focusing on the formula: “R[-4] C + R[-3] C - R[-2] C “
  • 26. D_ Recording some VBA Macros ActiveCell.Offset( Up/Down CellStep, Left/Right CellStep) Relative Recording
  • 27. D_ Recording some VBA Macros Calling both MyMacro01 and MyMacro02
  • 28. D_ Recording some VBA Macros
  • 29. D_ Recording some VBA Macros
  • 30. D_ Recording some VBA Macros Clearing the area BackToTOC BackToD
  • 31. E_ Running the macros Alt+F8 Analyzing the recorded macros Tan_E_Slide
  • 32. E_ Running the macros
  • 33. E_ Running the macros
  • 34. E_ Running the macros BackToTOC BackToE
  • 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
  • 41. G_ UserForm Example Call Demo G Tan_G_Slide
  • 48. H_ Overall Structure Application Project Worksheets Modules User_Form Macro Window Buttons Call Form Read/Write Data BackToTOC