SlideShare a Scribd company logo
1 of 31
Mr.Sameh Aljabli
 An abbreviation for Visual Basic for Applications
 Official name is "Visual Basic, Applications Edition."
 VBA is Microsoft's common application programming
(macro) language for Word, Excel, Access, etc.
 Also being implemented in other Microsoft applications
such as Visio and is at least partially implemented in some
other applications such as AutoCAD...
 VBA and VB have a lot in common, but they are different.
VB is a programming language that lets you create
standalone executable programs.
 Write Macros to Automate Labor-Intensive and Repetitive
Tasks
 Create User-Defined Functions to Achieve Complicated
Functionality
 Create Standard Windows Menu/Tool Bars for Interface
 Interact with Other Windows Programs (like Matlab)
 I/O with External Files
 Database Operation ….
 C++, Java, etc. are OOP (Object Oriented Programming)
Language
 VBA is an Object Based Programming Language
 What is Object?
 Concepts – Containers or Collections
◦ A Group of Similar Objects Share Common Properties,
Methods and Events
◦ Such as Workbooks, Worksheets, etc.
◦ Worksheets is a collection of all the Worksheet objects in the
specified or active workbook.
◦ Worksheets(1) refers to the 1st worksheet of current active
workbook.
◦ Worksheets (“Sheet1”) refers to the worksheet named
“Sheet1”.
An Introduction to VBA
- VBA Object Based Programming Language
 Concepts – Objects
 Such as Worksheet, Workbook, Range, Cell, Chart,
Name, etc.
 Worksheets(1) is an Object Referring to the First Sheet
 Range("A1:B15") is an Object Referring to a Range
 Cells(1,1) or Range(“A1”) is an Object Referring to
Range “A1”
An Introduction to VBA
- VBA Object Based Programming Language
 Concepts – Properties
 Properties are the Physical Characteristics of Objects
and Can be Measured or Quantified.
 Properties for Collections
 - Worksheets.Count (Read Only)
 - Worksheets.Visible = True (Read and Write)
 Properties for Object
 - Range("A1:B15").Rows.Count (Read Only)
 - Range("A1:B15").Font.Bold = True (Read and Write)
An Introduction to VBA
- VBA Object Based Programming Language
 Concepts – Methods
 Methods are the Actions that Can be Performed by
Objects or on Objects
 Methods for Collections
 - Worksheets.Add
 - Worksheets.Delete
 Methods for Objects
 - Range("A1:B15").ClearContents
 - ActiveCell.Copy
An Introduction to VBA
- VBA Object Based Programming Language
 Concepts – Events
 Objects Can Respond to Events, Such as Mouse Click,
Double Click on a Cell, Active a Worksheet,
Open/Close/Save a Workbook, etc.
 Worksheet Events –
 Such as Activate, Deactivate, Change, Selection
Change, Before Double Click, etc.
 Workbook Events-
 Such as Activate, Deactivate, Open, Before Close,
Before Saving, Before Print, New Sheet.
An Introduction to VBA
- VBA Object Based Programming Language
 Concepts – Referring To
 Use brackets () to refer to member object
 Worksheets(“Sheet1”)
 Use dot . to refer to child object or object’s
properties and methods
 Worksheets(“Sheet1”).Range(“A1:B3”).Font.Bold
An Introduction to VBA
- VBA Object Based Programming Language
 Concept
Summary
Collections
(worksheets)
Objects
(worksheet)
Properties
name
Method
Add
Event
Activate
An Introduction to VBA
- VBA Object Based Programming Language
 Understand Object Concepts
Workbooks("book1.xls").Worksheets("sheet1").Range("A1").Font.Bold = True
ActiveWorkbook.ActiveSheet.Cells(1, 1).ClearContents
Private Sub Workbook_Open()
MsgBox "Thank you for choosing VBA"
End Sub
An Introduction to VBA
- First Step to VBA : Macros
 Record Macro
 Similar to audio/video recorder
 Record all the steps you conduct and write them
in VBA code
An Introduction to VBA
- First Step to VBA : Macros
 Assign Macro to An Event
 Normally User Run Macros from VBA Edit
Window – Unnecessary
 User Can Assign Macro to An Event, Normally a
Button Click Event
 Easy to Execute and Easy to Remember
 Give a Good Name for The Button and Click the
Button to Run the Macro
An Introduction to VBA
- First Step to VBA : Macros
 Assign Macro to An Event
An Introduction to VBA
- Second Step to VBA : Edit Macro
 VBA Editor Window
 Press Alt+F11 to Activate VBA Window
 Or Go to Menu Developer >Visual Basic
 Project Explore Window
 Properties Window
 Code Window
An Introduction to VBA
- Second Step to VBA : Edit Macro
 VBA Editor Window
 Use Tools/Options to Enable Auto Syntax
Check, Auto List Members, etc.
 Use Tools/Properties to Protect Your Code with
Password – You Must Remember the Password
 Insert Module, Procedure, Form
An Introduction to VBA
- Second Step to VBA : Edit Macro
 Sample
 Record Macro
 Understand Macro
 Modify Macro
 Assign Macro to Button Click Event
An Introduction to VBA
- Second Step to VBA : Edit Macro
 Understand VBA Editor Window
Project window
Shows files, sheets
and modules
Property window
Show properties of
active object and
let user to modify
the properties
Code window
VBA codes are
here.
Auto list member
Auto list data /
parameter
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Fundamental of VBA
 Variables: can be define explicit or implicit use dim statement
 Constant use const pi =3.1415926
 Function: pair of function … end function
 Subroutine: pair of sub … end sub
 Comment use single quotation ‘
Assign object use set and assign data variable use =
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Fundamental of VBA
 Decision Making use If… elseif…else…end if
 Multiple Selection/Decision Making
Select Case Var… Case A … Case B…Case Else… End Select
 Loop use
Do While … Loop Do … Loop Until
For … Next For Each … Next
 Array – dim Data(10) as integer , Val(2 to 8) as object
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Fundamental of VBA
 Function
 Public , Private, Return Value
 Parameter
 Subroutine
 Public, Private, No Return Value
 Parameter
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Understand Code
Worksheets("sheet1").Activate
Range("A1:A10").ClearContents
For i = 1 To 10
Range("A" & i) = i ^ 2
Next
Range("A1:A10").Font.Bold = True
For Each cl In Range("A1:A10")
If cl.Value < 25 Or cl.Value > 75 Then
cl.Font.Italic = True
Else
cl.Font.Underline = True
End If
Next
Msgbox “All done”
1) Make sheet1 active
2) Clear range A1:A10
3) Type 1,4,9,…100 in to range
A1, A2, … A10
4) Set font to bold for all cells in
the range
5) Make cell italic if the cell’s
value is <25 or >75,
otherwise underline
6) Display message “All done”
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Create User-Defined Functions
Public Function myFun(x As Integer, y As Integer) As Integer
myFun = x * y + x / y
End Function
Must start with
Keyword “Function”
and end with “End
Function”
Arguments Return Value Type
The return value must be
assigned to the function name
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Work
with
Workbook
' Refer A Workbook
Workbooks(1) ' Use Index
Workbooks("Results.Xls") ' Use Name
ActiveWorkbook ' Refers to the Active Workbook
' Create A New Workbook
Dim NewWkBk as Workbook
Set NewWkBk = Workbooks.Add
With NewWkBk
.Title = "Analysis Resultd"
.Subject = "Results for Analysis"
.SaveAs Filename:="Results.xls"
End With
Use With
Statement
(faster)
An Introduction to VBA
- Third Step to VBA : Write VBA Code
' Open / Activate / Save /Close Workbook
Fname ="C:AnalysisResutlsResults.xls"
Workbooks.Open(Fname)
Workbooks("Results.xls").Activate
Workbooks("Results.xls").Save
Workbooks("Results.xls").Close SaveChanges:=True ‘
' Loop All Open Workbooks
Dim wkbk As Workbook
For Each wkbk In Workbooks
Msgbox "Workbook " & wkbk.Name
Next
For Each
Statement
An Introduction to VBA
- Third Step to VBA : Write VBA Code
 Work
with
Worksheet
' Refer A Worksheet
Worksheets(1) ' Use Index
Worksheets("Sheet1") ' Use Name
ActiveWorksheet ' Active Worksheet
Workbooks("TestSht.xls").Worksheets("Sht2")
' Add /Activate/Delete A New Worksheet
Workbooks("TestSht.xls").Worksheets.Add
Sheets("NewSht").Activate
Workbooks(“A.xls").Sheets(“B").Activate
Sheets("NewSht").Delete
An Introduction to VBA
- Third Step to VBA : Write VBA Code
‘Rename / Extract A Worksheet
Workbooks("TestSht.xls").Sheets("NewSht").name = "NewSht2"
MsgBox "Current Sheet Name is " & ActiveSheet.Name
' Count Sheets
MsgBox "Current Workbook Has " & Sheets.Count & " sheets"
' Loop All Sheets
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Sheets
MsgBox sht.Name & " A1 = " & Range(“A1").Value
Next
variable = cell (reading one value)
5S =
S=Range(“A1”)
S=Range (“Start”)
S=Cells(1,1)
Cells(row index, column index)
returns value of specified cell
An Introduction to VBA
- Third Step to VBA : Write VBA Code
range = expression
5
Range(“A1”) = “last name”
Range (“Start”) = “last name”
Cells(1,2) = SUM (B1:B7)
Cells(1,1) = 5
An Introduction to VBA
- Third Step to VBA : Write VBA Code
An Introduction to VBA
- Third Step to VBA : Write VBA Code
With sht ' use with to speed up and save typing
.Name = "Summary2"
.Range("A1").Value = "Case Name"
.Range("A2") = "Case ID" ' default property is value
.Range("A3") = "Weight"
.Range("A4") = "XCG"
.Range("A5") = "YCG"
.Range("A6") = "ZCG"
.Range("A1:A6").Font.Bold = True
.Range("A1:A6").HorizontalAlignment = xlLeft
 Review/Understand of Our First Macro

More Related Content

What's hot

MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPAli Shah
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorialvikram singh
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6BlackRabbitCoder
 
Working smart with excel v2.0
Working smart with excel v2.0Working smart with excel v2.0
Working smart with excel v2.0Romy Cagampan
 
VBA for technical writers
VBA for technical writersVBA for technical writers
VBA for technical writersTCUK
 

What's hot (13)

Java script basics
Java script basicsJava script basics
Java script basics
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
VBA
VBAVBA
VBA
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
WPF Concepts
WPF ConceptsWPF Concepts
WPF Concepts
 
Books
BooksBooks
Books
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
 
Mvc by asp.net development company in india - part 2
Mvc by asp.net development company in india  - part 2Mvc by asp.net development company in india  - part 2
Mvc by asp.net development company in india - part 2
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6
 
Working smart with excel v2.0
Working smart with excel v2.0Working smart with excel v2.0
Working smart with excel v2.0
 
VBA for technical writers
VBA for technical writersVBA for technical writers
VBA for technical writers
 

Similar to Financial modeling sameh aljabli lecture 6

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
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1guest38bf
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basicsHang Dong
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosExcel
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)pbarasia
 
Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)Mark Vincent Cantero
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan
 
AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1Dan D'Urso
 

Similar to Financial modeling sameh aljabli lecture 6 (20)

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
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
Vba primer
Vba primerVba primer
Vba primer
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basics
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 Macros
 
Improved VBA support
Improved VBA supportImproved VBA support
Improved VBA support
 
Vba introduction
Vba introductionVba introduction
Vba introduction
 
Matlab OOP
Matlab OOPMatlab OOP
Matlab OOP
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Excel 2007 Unit P
Excel 2007 Unit PExcel 2007 Unit P
Excel 2007 Unit P
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
Automating SolidWorks with Excel
Automating SolidWorks with ExcelAutomating SolidWorks with Excel
Automating SolidWorks with Excel
 
I x scripting
I x scriptingI x scripting
I x scripting
 
Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)Introduction to visual basic 6 (1)
Introduction to visual basic 6 (1)
 
Vb 6ch123
Vb 6ch123Vb 6ch123
Vb 6ch123
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
 
AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1AVB201.1 Microsoft Access VBA Module 1
AVB201.1 Microsoft Access VBA Module 1
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Intro_to_VB.PPT
Intro_to_VB.PPTIntro_to_VB.PPT
Intro_to_VB.PPT
 

More from Sameh Algabli

Financial modeling sameh aljabli lecture 5
Financial modeling   sameh aljabli   lecture 5Financial modeling   sameh aljabli   lecture 5
Financial modeling sameh aljabli lecture 5Sameh Algabli
 
Financial modeling sameh aljabli lecture 3
Financial modeling   sameh aljabli   lecture 3Financial modeling   sameh aljabli   lecture 3
Financial modeling sameh aljabli lecture 3Sameh Algabli
 
Financial modeling sameh aljabli - lecture 2
Financial modeling   sameh aljabli - lecture 2Financial modeling   sameh aljabli - lecture 2
Financial modeling sameh aljabli - lecture 2Sameh Algabli
 
Financial modeling sameh aljabli - lecture 1
Financial modeling   sameh aljabli - lecture 1Financial modeling   sameh aljabli - lecture 1
Financial modeling sameh aljabli - lecture 1Sameh Algabli
 
Harley &amp; davidson mba - marketing management - case study presentation
Harley &amp; davidson   mba - marketing management - case study presentationHarley &amp; davidson   mba - marketing management - case study presentation
Harley &amp; davidson mba - marketing management - case study presentationSameh Algabli
 

More from Sameh Algabli (6)

Financial modeling sameh aljabli lecture 5
Financial modeling   sameh aljabli   lecture 5Financial modeling   sameh aljabli   lecture 5
Financial modeling sameh aljabli lecture 5
 
Financial modeling sameh aljabli lecture 3
Financial modeling   sameh aljabli   lecture 3Financial modeling   sameh aljabli   lecture 3
Financial modeling sameh aljabli lecture 3
 
Financial modeling sameh aljabli - lecture 2
Financial modeling   sameh aljabli - lecture 2Financial modeling   sameh aljabli - lecture 2
Financial modeling sameh aljabli - lecture 2
 
Financial modeling sameh aljabli - lecture 1
Financial modeling   sameh aljabli - lecture 1Financial modeling   sameh aljabli - lecture 1
Financial modeling sameh aljabli - lecture 1
 
Harley &amp; davidson mba - marketing management - case study presentation
Harley &amp; davidson   mba - marketing management - case study presentationHarley &amp; davidson   mba - marketing management - case study presentation
Harley &amp; davidson mba - marketing management - case study presentation
 
Erp next hr-modules
Erp next hr-modulesErp next hr-modules
Erp next hr-modules
 

Recently uploaded

Vip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts ServiceVip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts Serviceankitnayak356677
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsApsara Of India
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africaictsugar
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...lizamodels9
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...ictsugar
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...lizamodels9
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCRashishs7044
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessAggregage
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCRashishs7044
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCRashishs7044
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 

Recently uploaded (20)

Vip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts ServiceVip Female Escorts Noida 9711199171 Greater Noida Escorts Service
Vip Female Escorts Noida 9711199171 Greater Noida Escorts Service
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call GirlsCash Payment 9602870969 Escort Service in Udaipur Call Girls
Cash Payment 9602870969 Escort Service in Udaipur Call Girls
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africa
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR8447779800, Low rate Call girls in Rohini Delhi NCR
8447779800, Low rate Call girls in Rohini Delhi NCR
 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for Success
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 

Financial modeling sameh aljabli lecture 6

  • 2.  An abbreviation for Visual Basic for Applications  Official name is "Visual Basic, Applications Edition."  VBA is Microsoft's common application programming (macro) language for Word, Excel, Access, etc.  Also being implemented in other Microsoft applications such as Visio and is at least partially implemented in some other applications such as AutoCAD...  VBA and VB have a lot in common, but they are different. VB is a programming language that lets you create standalone executable programs.
  • 3.  Write Macros to Automate Labor-Intensive and Repetitive Tasks  Create User-Defined Functions to Achieve Complicated Functionality  Create Standard Windows Menu/Tool Bars for Interface  Interact with Other Windows Programs (like Matlab)  I/O with External Files  Database Operation ….
  • 4.  C++, Java, etc. are OOP (Object Oriented Programming) Language  VBA is an Object Based Programming Language  What is Object?
  • 5.  Concepts – Containers or Collections ◦ A Group of Similar Objects Share Common Properties, Methods and Events ◦ Such as Workbooks, Worksheets, etc. ◦ Worksheets is a collection of all the Worksheet objects in the specified or active workbook. ◦ Worksheets(1) refers to the 1st worksheet of current active workbook. ◦ Worksheets (“Sheet1”) refers to the worksheet named “Sheet1”.
  • 6. An Introduction to VBA - VBA Object Based Programming Language  Concepts – Objects  Such as Worksheet, Workbook, Range, Cell, Chart, Name, etc.  Worksheets(1) is an Object Referring to the First Sheet  Range("A1:B15") is an Object Referring to a Range  Cells(1,1) or Range(“A1”) is an Object Referring to Range “A1”
  • 7. An Introduction to VBA - VBA Object Based Programming Language  Concepts – Properties  Properties are the Physical Characteristics of Objects and Can be Measured or Quantified.  Properties for Collections  - Worksheets.Count (Read Only)  - Worksheets.Visible = True (Read and Write)  Properties for Object  - Range("A1:B15").Rows.Count (Read Only)  - Range("A1:B15").Font.Bold = True (Read and Write)
  • 8. An Introduction to VBA - VBA Object Based Programming Language  Concepts – Methods  Methods are the Actions that Can be Performed by Objects or on Objects  Methods for Collections  - Worksheets.Add  - Worksheets.Delete  Methods for Objects  - Range("A1:B15").ClearContents  - ActiveCell.Copy
  • 9. An Introduction to VBA - VBA Object Based Programming Language  Concepts – Events  Objects Can Respond to Events, Such as Mouse Click, Double Click on a Cell, Active a Worksheet, Open/Close/Save a Workbook, etc.  Worksheet Events –  Such as Activate, Deactivate, Change, Selection Change, Before Double Click, etc.  Workbook Events-  Such as Activate, Deactivate, Open, Before Close, Before Saving, Before Print, New Sheet.
  • 10. An Introduction to VBA - VBA Object Based Programming Language  Concepts – Referring To  Use brackets () to refer to member object  Worksheets(“Sheet1”)  Use dot . to refer to child object or object’s properties and methods  Worksheets(“Sheet1”).Range(“A1:B3”).Font.Bold
  • 11. An Introduction to VBA - VBA Object Based Programming Language  Concept Summary Collections (worksheets) Objects (worksheet) Properties name Method Add Event Activate
  • 12. An Introduction to VBA - VBA Object Based Programming Language  Understand Object Concepts Workbooks("book1.xls").Worksheets("sheet1").Range("A1").Font.Bold = True ActiveWorkbook.ActiveSheet.Cells(1, 1).ClearContents Private Sub Workbook_Open() MsgBox "Thank you for choosing VBA" End Sub
  • 13. An Introduction to VBA - First Step to VBA : Macros  Record Macro  Similar to audio/video recorder  Record all the steps you conduct and write them in VBA code
  • 14. An Introduction to VBA - First Step to VBA : Macros  Assign Macro to An Event  Normally User Run Macros from VBA Edit Window – Unnecessary  User Can Assign Macro to An Event, Normally a Button Click Event  Easy to Execute and Easy to Remember  Give a Good Name for The Button and Click the Button to Run the Macro
  • 15. An Introduction to VBA - First Step to VBA : Macros  Assign Macro to An Event
  • 16. An Introduction to VBA - Second Step to VBA : Edit Macro  VBA Editor Window  Press Alt+F11 to Activate VBA Window  Or Go to Menu Developer >Visual Basic  Project Explore Window  Properties Window  Code Window
  • 17. An Introduction to VBA - Second Step to VBA : Edit Macro  VBA Editor Window  Use Tools/Options to Enable Auto Syntax Check, Auto List Members, etc.  Use Tools/Properties to Protect Your Code with Password – You Must Remember the Password  Insert Module, Procedure, Form
  • 18. An Introduction to VBA - Second Step to VBA : Edit Macro  Sample  Record Macro  Understand Macro  Modify Macro  Assign Macro to Button Click Event
  • 19. An Introduction to VBA - Second Step to VBA : Edit Macro  Understand VBA Editor Window Project window Shows files, sheets and modules Property window Show properties of active object and let user to modify the properties Code window VBA codes are here. Auto list member Auto list data / parameter
  • 20. An Introduction to VBA - Third Step to VBA : Write VBA Code  Fundamental of VBA  Variables: can be define explicit or implicit use dim statement  Constant use const pi =3.1415926  Function: pair of function … end function  Subroutine: pair of sub … end sub  Comment use single quotation ‘ Assign object use set and assign data variable use =
  • 21. An Introduction to VBA - Third Step to VBA : Write VBA Code  Fundamental of VBA  Decision Making use If… elseif…else…end if  Multiple Selection/Decision Making Select Case Var… Case A … Case B…Case Else… End Select  Loop use Do While … Loop Do … Loop Until For … Next For Each … Next  Array – dim Data(10) as integer , Val(2 to 8) as object
  • 22. An Introduction to VBA - Third Step to VBA : Write VBA Code  Fundamental of VBA  Function  Public , Private, Return Value  Parameter  Subroutine  Public, Private, No Return Value  Parameter
  • 23. An Introduction to VBA - Third Step to VBA : Write VBA Code  Understand Code Worksheets("sheet1").Activate Range("A1:A10").ClearContents For i = 1 To 10 Range("A" & i) = i ^ 2 Next Range("A1:A10").Font.Bold = True For Each cl In Range("A1:A10") If cl.Value < 25 Or cl.Value > 75 Then cl.Font.Italic = True Else cl.Font.Underline = True End If Next Msgbox “All done” 1) Make sheet1 active 2) Clear range A1:A10 3) Type 1,4,9,…100 in to range A1, A2, … A10 4) Set font to bold for all cells in the range 5) Make cell italic if the cell’s value is <25 or >75, otherwise underline 6) Display message “All done”
  • 24. An Introduction to VBA - Third Step to VBA : Write VBA Code  Create User-Defined Functions Public Function myFun(x As Integer, y As Integer) As Integer myFun = x * y + x / y End Function Must start with Keyword “Function” and end with “End Function” Arguments Return Value Type The return value must be assigned to the function name
  • 25. An Introduction to VBA - Third Step to VBA : Write VBA Code  Work with Workbook ' Refer A Workbook Workbooks(1) ' Use Index Workbooks("Results.Xls") ' Use Name ActiveWorkbook ' Refers to the Active Workbook ' Create A New Workbook Dim NewWkBk as Workbook Set NewWkBk = Workbooks.Add With NewWkBk .Title = "Analysis Resultd" .Subject = "Results for Analysis" .SaveAs Filename:="Results.xls" End With Use With Statement (faster)
  • 26. An Introduction to VBA - Third Step to VBA : Write VBA Code ' Open / Activate / Save /Close Workbook Fname ="C:AnalysisResutlsResults.xls" Workbooks.Open(Fname) Workbooks("Results.xls").Activate Workbooks("Results.xls").Save Workbooks("Results.xls").Close SaveChanges:=True ‘ ' Loop All Open Workbooks Dim wkbk As Workbook For Each wkbk In Workbooks Msgbox "Workbook " & wkbk.Name Next For Each Statement
  • 27. An Introduction to VBA - Third Step to VBA : Write VBA Code  Work with Worksheet ' Refer A Worksheet Worksheets(1) ' Use Index Worksheets("Sheet1") ' Use Name ActiveWorksheet ' Active Worksheet Workbooks("TestSht.xls").Worksheets("Sht2") ' Add /Activate/Delete A New Worksheet Workbooks("TestSht.xls").Worksheets.Add Sheets("NewSht").Activate Workbooks(“A.xls").Sheets(“B").Activate Sheets("NewSht").Delete
  • 28. An Introduction to VBA - Third Step to VBA : Write VBA Code ‘Rename / Extract A Worksheet Workbooks("TestSht.xls").Sheets("NewSht").name = "NewSht2" MsgBox "Current Sheet Name is " & ActiveSheet.Name ' Count Sheets MsgBox "Current Workbook Has " & Sheets.Count & " sheets" ' Loop All Sheets Dim sht As Worksheet For Each sht In ActiveWorkbook.Sheets MsgBox sht.Name & " A1 = " & Range(“A1").Value Next
  • 29. variable = cell (reading one value) 5S = S=Range(“A1”) S=Range (“Start”) S=Cells(1,1) Cells(row index, column index) returns value of specified cell An Introduction to VBA - Third Step to VBA : Write VBA Code
  • 30. range = expression 5 Range(“A1”) = “last name” Range (“Start”) = “last name” Cells(1,2) = SUM (B1:B7) Cells(1,1) = 5 An Introduction to VBA - Third Step to VBA : Write VBA Code
  • 31. An Introduction to VBA - Third Step to VBA : Write VBA Code With sht ' use with to speed up and save typing .Name = "Summary2" .Range("A1").Value = "Case Name" .Range("A2") = "Case ID" ' default property is value .Range("A3") = "Weight" .Range("A4") = "XCG" .Range("A5") = "YCG" .Range("A6") = "ZCG" .Range("A1:A6").Font.Bold = True .Range("A1:A6").HorizontalAlignment = xlLeft  Review/Understand of Our First Macro