SlideShare a Scribd company logo
Excel and
the VBELECTURE 1
Important things to know in Excel
The VBE environment
A first go at some coding!
SUMMARY
IMPORTANT THINGS TO
KNOW ABOUT EXCEL
CELL REFERENCES IN EXCEL
Each cell has an ‘address’:
“B5” Row 5, Column B.
R5C2 Row 5, Column 2.
R5
C2
B5
CELL REFERENCES IN EXCEL
Each cell has an ‘address’:
“B5” Row 5, Column B.
R5C2 Row 5, Column 2.
Cells(5,2) Row 5, Column 2.
Preferred notation
within VBA because
it can be looped.
R5
C2
Cells(5,2)
 A range can be:
One cell (e.g., G2), or
NAMING RANGES
 A range can be:
One cell (e.g., G2), or
Multiple cells, which are next to each other (e.g., A2:E2)
NAMING RANGES
 What’s the benefit of naming ranges?
If you move a named range:
 The cell reference changes, but
 The range name does not change
 What’s that mean for you, the programmer?
If you refer to a cell reference (e.g., G2), in your code,
…and then move the contents of that cell
…you have to go back and update your code
If you refer to a named range (e.g., “PortfolioReturn”), in
your code
…and then move the contents of that cell (cut + paste)
…you don’t have to update your code.
NAMING RANGES
A few rules…
MUST start with a letter
CANNOT contain any spaces
CANNOT be the name of another range
CANNOT be the name of the cell reference for another cell
in Excel.
NAMING RANGES
“RET1” is already a cell in Excel so I can’t give another cell this name.
1. SAVE AS .xlsm
2. Save FREQUENTLY!! Excel crashes!
3. Saving your Excel workbook ALSO saves your VBA.
4. Use good files names so that you know which file
is the newest version you’re working on.
• Dissertation.xlsm
• Disso.xlsm
• myDisso.xlsm
• DissoNew.xlsm
• DissoNewest.xlsm
SAVING YOUR WORK
m for Macro Enabled
• 13oct04Dissertation.xlsm
• 2013oct04_Disso.xlsm
• 04oct13_myDisso.xlsm
Visual
Basic
Editor
THE VBE
GETTING FAMILIAR WITH THE VBE
Alt + F11: Toggle between Excel and VBE, OR
Go to the VBE
from Excel
Go back to Excel
from the VBE
GETTING FAMILIAR WITH THE VBE
Excel File This is where you
write your code
GETTING FAMILIAR WITH THE VBE
Code for
data in
Worksheets
goes here
Code in a specific sheet can
only be executed for data
and cells in that sheet.
You CANNOT refer to cells
in another worksheet or on
a userform
GETTING FAMILIAR WITH THE VBE
Commands
for the
Workbook
go here
For example
•Open the software when
the workbook opens
•Save the workbook when
the software closes
• Etc…
GETTING FAMILIAR WITH THE VBE
Code for
Userforms
go here
Code which uses or refers
to information obtained on
the userform
Code which executes when
tools on the userform are
used (e.g., command
buttons)
GETTING FAMILIAR WITH THE VBE
Other code,
not specific
to any one
userform or
worksheet
goes in a
module
For
calculations, optimisation,
or any code you want to be
able to use at any time
 Insert a Userform
GETTING FAMILIAR WITH THE VBE
 Insert a Userform
 Insert a module
GETTING FAMILIAR WITH THE VBE
 Insert a Userform
 Insert a module
 Insert a procedure
GETTING FAMILIAR WITH THE VBE
We’ll come back to this
later in the term
INSERT A PROCEDURE
You will use both
Sub’s and Function’s
during your FYP.
We will discuss the
difference later.
The name should be
descriptive of your
Sub or Function.
Cannot contain
spaces.
Click OK. This is what you should get:
Write your code here.
The Sub Procedure is now in the Module
EDITING EXCEL USING VBA
ACTIVATE A WORKBOOK
Name of my workbook in “ ”.
Tell VBA which workbook
you want to work with
ACTIVATE A WORKSHEET
Tell VBA which worksheet
you want to work with
Name of my worksheet in “ ”.
NAMING RANGES
Use .Name
Assign range names to…
• One cell, or
Must be in “ ”
because it’s text!
NAMING RANGES
Use .Name
Assign range names to…
• One cell, or
• A range of cells
Must be in “ ”
because it’s text!
NAMING RANGES
Assign range names to…
• One cell, or
• A range of cells
Row 7, Column 1 (top left)
Through to
Row 9, Column 3 (btm right)
ASSIGNING VALUES
Enter a number into…
• One cell, or
• A range of cells
InputBox(“ ”)
Used to get input from the user
ASSIGNING VALUES
Enter text into…
• One cell, or
• A range of cells
Text MUST be in “ ”
 Check the range names by clicking on the cells
 Did the code do what you thought it would?
RUN THIS CODE (PRESS F5)
USE EXCEL BUILT-IN FUNCTIONS FROM VBA
Activate the correct
worksheet
USE EXCEL BUILT-IN FUNCTIONS FROM VBA
Name the range where the
numbers are in Excel
USE EXCEL BUILT-IN FUNCTIONS FROM VBA
Enter column headings
USE EXCEL BUILT-IN FUNCTIONS FROM VBA
Three ways to do the same thing
Use what is best for the situation
Enters the equation
=Sum(numSeries)
into Row 2, Col 3.
USE EXCEL BUILT-IN FUNCTIONS FROM VBA
Uses the built in Min function
to find the minimum of the
range named numSeries.
Three ways to do the same thing
Use what is best for the situation
USE EXCEL BUILT-IN FUNCTIONS FROM VBA
Uses the built in Max function
to find the maximum of the range
from Rows 1 to 7 in Col 1.
Three ways to do the same thing
Use what is best for the situation
 In column 1 of your worksheet, create a list of 7 random
numbers.
 Insert a new Sub procedure called Exercise1.
 Enter & run the following code:
EXERCISE #1
 From the Developer Tab:
Choose Insert
Under Form Controls,
Select command Button
 Draw a command button.
 Select the macro you want to assign to this
button. Only procedures in Modules will appear
in the list.
EXECUTING CODE USING FORM CONTROLS.
Choose Exercise1
Turn off Design Mode.
 Make sure it is not highlighted
 Your button now runs the code from the Sub
Exercise1.
Try changing your random numbers & re-running
your code by using your button.
EXECUTING CODE USING FORM CONTROLS.
Create a Sub procedure called “Exercise2”
Code the following in this sub:
Activate your worksheet (use the sheet called ‘Example 3’)
Assign a range name to the range of weights
Assign a range name to the range of mean returns
Assign a range name to cell G2, which will contain a
formula for the portfolio return (next step)
Assign equal weights into the weights range
Enter the formula to calculate the portfolio return into G2
(use the SUMPRODUCT formula)
Run your code (Put your cursor inside the sub & hit F5).
Go back to Excel and make sure it’s correct.
EXERCISE #2
You are ready to move on when:
LO1: You can name the address of a cell using Cells(r,c) or
RC notation.
LO2: In the VBE, you know the difference between adding
code in a worksheet, a userform and a module.
LO3: You can name ranges within Excel as well as name
Excel ranges within VBA.
LO4: You can assign numerical or text values to individual
cells and ranges of cells from within VBA.
LO5: You can describe the difference between the 3 ways
of using Excel built-in functions within VBA.
LEARNING OUTCOMES
THE END

More Related Content

What's hot

Performing basic computation (Microsoft Excel)
Performing basic computation (Microsoft Excel)Performing basic computation (Microsoft Excel)
Performing basic computation (Microsoft Excel)
Mirea Mizushima
 
Summarize Data Using a Formula
Summarize Data Using a FormulaSummarize Data Using a Formula
Summarize Data Using a Formulacoachhahn
 
Excel functions formulas
Excel functions formulasExcel functions formulas
Excel functions formulasLearnIT@UD
 
50 MS Excel Tips and Tricks
50 MS Excel Tips and Tricks 50 MS Excel Tips and Tricks
50 MS Excel Tips and Tricks
BurCom Consulting Ltd.
 
Fill series. Data validation. Excel Tutorial
Fill series. Data validation. Excel TutorialFill series. Data validation. Excel Tutorial
Fill series. Data validation. Excel Tutorial
Ilgar Zarbaliyev
 
New Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel TutorialNew Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel Tutorial
Ilgar Zarbaliyev
 
How to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzalHow to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzal
1995786
 
Excel presentation
Excel presentationExcel presentation
Excel presentationDUSPviz
 
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot EngibaryanCommon MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Ashot Engibaryan
 
Excel Chapter 2 - Inserting Formulas in a Worksheet
Excel Chapter 2 - Inserting Formulas in a WorksheetExcel Chapter 2 - Inserting Formulas in a Worksheet
Excel Chapter 2 - Inserting Formulas in a Worksheetdpd
 
Chapter 1 lesson 2 MS Excel and its Interface
Chapter 1 lesson 2 MS Excel and its InterfaceChapter 1 lesson 2 MS Excel and its Interface
Chapter 1 lesson 2 MS Excel and its InterfaceRonnel de Jesus
 
Excel Basics 2
Excel Basics 2Excel Basics 2
Excel Basics 2
Leslie Noggle
 
090225 Excel Training
090225 Excel Training090225 Excel Training
090225 Excel Training
michael.komarnitsky
 
Basic Formulas - Excel 2013 Tutorial
Basic Formulas - Excel 2013 TutorialBasic Formulas - Excel 2013 Tutorial
Basic Formulas - Excel 2013 Tutorial
SpreadsheetTrainer
 
Functions and Charts in Microsoft Excel
Functions and Charts in Microsoft ExcelFunctions and Charts in Microsoft Excel
Functions and Charts in Microsoft Excel
North Bend Public Library
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
DHRUYEN HADIYA
 

What's hot (20)

Performing basic computation (Microsoft Excel)
Performing basic computation (Microsoft Excel)Performing basic computation (Microsoft Excel)
Performing basic computation (Microsoft Excel)
 
Summarize Data Using a Formula
Summarize Data Using a FormulaSummarize Data Using a Formula
Summarize Data Using a Formula
 
Excel functions formulas
Excel functions formulasExcel functions formulas
Excel functions formulas
 
50 MS Excel Tips and Tricks
50 MS Excel Tips and Tricks 50 MS Excel Tips and Tricks
50 MS Excel Tips and Tricks
 
Fill series. Data validation. Excel Tutorial
Fill series. Data validation. Excel TutorialFill series. Data validation. Excel Tutorial
Fill series. Data validation. Excel Tutorial
 
New Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel TutorialNew Dynamic Array Functions. Excel Tutorial
New Dynamic Array Functions. Excel Tutorial
 
Lesson 5
Lesson 5Lesson 5
Lesson 5
 
How to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzalHow to apply a formula and macro in excel......by irfan afzal
How to apply a formula and macro in excel......by irfan afzal
 
Fieldsymbols
FieldsymbolsFieldsymbols
Fieldsymbols
 
Excel presentation
Excel presentationExcel presentation
Excel presentation
 
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot EngibaryanCommon MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
Common MS Excel and MS Excel 2013 useful tricks. By Ashot Engibaryan
 
Excel Chapter 2 - Inserting Formulas in a Worksheet
Excel Chapter 2 - Inserting Formulas in a WorksheetExcel Chapter 2 - Inserting Formulas in a Worksheet
Excel Chapter 2 - Inserting Formulas in a Worksheet
 
Chapter 1 lesson 2 MS Excel and its Interface
Chapter 1 lesson 2 MS Excel and its InterfaceChapter 1 lesson 2 MS Excel and its Interface
Chapter 1 lesson 2 MS Excel and its Interface
 
Excel Basics 2
Excel Basics 2Excel Basics 2
Excel Basics 2
 
Using Formulas in Excel
Using Formulas in ExcelUsing Formulas in Excel
Using Formulas in Excel
 
090225 Excel Training
090225 Excel Training090225 Excel Training
090225 Excel Training
 
Basic Formulas - Excel 2013 Tutorial
Basic Formulas - Excel 2013 TutorialBasic Formulas - Excel 2013 Tutorial
Basic Formulas - Excel 2013 Tutorial
 
Functions and Charts in Microsoft Excel
Functions and Charts in Microsoft ExcelFunctions and Charts in Microsoft Excel
Functions and Charts in Microsoft Excel
 
MS Excel 2nd
MS Excel 2ndMS Excel 2nd
MS Excel 2nd
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
 

Viewers also liked

Unit 8 assignment 2a teona mc fadden finish tonight
Unit 8 assignment 2a  teona mc fadden finish tonightUnit 8 assignment 2a  teona mc fadden finish tonight
Unit 8 assignment 2a teona mc fadden finish tonightteonamaud
 
The ultimate guide to cost management
The ultimate guide to cost managementThe ultimate guide to cost management
The ultimate guide to cost management
Tim Kalbitzer
 
SPSHOU SharePoint 2013 Best Practices
SPSHOU SharePoint 2013 Best PracticesSPSHOU SharePoint 2013 Best Practices
SPSHOU SharePoint 2013 Best Practices
Theresa Lubelski
 
Forms, Getting Your Money's Worth
Forms, Getting Your Money's WorthForms, Getting Your Money's Worth
Forms, Getting Your Money's Worth
Alex Gaynor
 
Cem 350 control systems 9 2016
Cem 350 control systems 9 2016Cem 350 control systems 9 2016
Cem 350 control systems 9 2016
miresmaeil
 
Sketchnote Collection 1 - Sacha Chua
Sketchnote Collection 1 - Sacha ChuaSketchnote Collection 1 - Sacha Chua
Sketchnote Collection 1 - Sacha Chua
Sacha Chua
 
Project Monitoring and Control
Project Monitoring and ControlProject Monitoring and Control
Project Monitoring and Control
guy_davis
 
Project Controlling and Project Monitoring
Project Controlling and Project MonitoringProject Controlling and Project Monitoring
Project Controlling and Project Monitoringharoldtaylor1113
 
Practical Sketchnoting
Practical SketchnotingPractical Sketchnoting
Practical Sketchnoting
Jason Alderman
 
How to build an Intranet portal in SharePoint using out of the box features
How to build an Intranet portal in SharePoint using out of the box featuresHow to build an Intranet portal in SharePoint using out of the box features
How to build an Intranet portal in SharePoint using out of the box features
Gregory Zelfond
 
Hvac presentation for beginers
Hvac presentation for beginersHvac presentation for beginers
Hvac presentation for beginers
guestf11b52
 
The Sketchnote Mini-Workshop
The Sketchnote Mini-WorkshopThe Sketchnote Mini-Workshop
The Sketchnote Mini-Workshop
Mike Rohde
 
Sketchnoting: 10 Tips to get Started
Sketchnoting: 10 Tips to get StartedSketchnoting: 10 Tips to get Started
Sketchnoting: 10 Tips to get Started
Silvia Rosenthal Tolisano
 

Viewers also liked (13)

Unit 8 assignment 2a teona mc fadden finish tonight
Unit 8 assignment 2a  teona mc fadden finish tonightUnit 8 assignment 2a  teona mc fadden finish tonight
Unit 8 assignment 2a teona mc fadden finish tonight
 
The ultimate guide to cost management
The ultimate guide to cost managementThe ultimate guide to cost management
The ultimate guide to cost management
 
SPSHOU SharePoint 2013 Best Practices
SPSHOU SharePoint 2013 Best PracticesSPSHOU SharePoint 2013 Best Practices
SPSHOU SharePoint 2013 Best Practices
 
Forms, Getting Your Money's Worth
Forms, Getting Your Money's WorthForms, Getting Your Money's Worth
Forms, Getting Your Money's Worth
 
Cem 350 control systems 9 2016
Cem 350 control systems 9 2016Cem 350 control systems 9 2016
Cem 350 control systems 9 2016
 
Sketchnote Collection 1 - Sacha Chua
Sketchnote Collection 1 - Sacha ChuaSketchnote Collection 1 - Sacha Chua
Sketchnote Collection 1 - Sacha Chua
 
Project Monitoring and Control
Project Monitoring and ControlProject Monitoring and Control
Project Monitoring and Control
 
Project Controlling and Project Monitoring
Project Controlling and Project MonitoringProject Controlling and Project Monitoring
Project Controlling and Project Monitoring
 
Practical Sketchnoting
Practical SketchnotingPractical Sketchnoting
Practical Sketchnoting
 
How to build an Intranet portal in SharePoint using out of the box features
How to build an Intranet portal in SharePoint using out of the box featuresHow to build an Intranet portal in SharePoint using out of the box features
How to build an Intranet portal in SharePoint using out of the box features
 
Hvac presentation for beginers
Hvac presentation for beginersHvac presentation for beginers
Hvac presentation for beginers
 
The Sketchnote Mini-Workshop
The Sketchnote Mini-WorkshopThe Sketchnote Mini-Workshop
The Sketchnote Mini-Workshop
 
Sketchnoting: 10 Tips to get Started
Sketchnoting: 10 Tips to get StartedSketchnoting: 10 Tips to get Started
Sketchnoting: 10 Tips to get Started
 

Similar to Ma3696 Lecture 1

Vba part 1
Vba part 1Vba part 1
Vba part 1
Morteza Noshad
 
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
DannySingh23
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
Morteza Noshad
 
Excel useful tips
Excel useful tipsExcel useful tips
Excel useful tips
Mohsin Azad
 
Excel tips
Excel tipsExcel tips
Excel tips
Ashish Patel
 
Excel Useful Tips
Excel Useful TipsExcel Useful Tips
Excel Useful Tips
Srinath Maharana
 
35 Useful Excel Tips
35 Useful Excel Tips35 Useful Excel Tips
35 Useful Excel Tips
Mukunda Adhikari
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptx
CliffordBorromeo
 
Spreadsheets[1]
Spreadsheets[1]Spreadsheets[1]
Spreadsheets[1]
BBAMUMU2014
 
Excel Formulas Functions
Excel Formulas FunctionsExcel Formulas Functions
Excel Formulas Functionssimply_coool
 
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 Formulas Functions 2007
Excel Formulas Functions 2007Excel Formulas Functions 2007
Excel Formulas Functions 2007simply_coool
 
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
 

Similar to Ma3696 Lecture 1 (20)

MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
Excel useful tips
Excel useful tipsExcel useful tips
Excel useful tips
 
Excel useful tips
Excel useful tipsExcel useful tips
Excel useful tips
 
Excel tips
Excel tipsExcel tips
Excel tips
 
Excel tips
Excel tipsExcel tips
Excel tips
 
Excel Useful Tips
Excel Useful TipsExcel Useful Tips
Excel Useful Tips
 
35 Useful Excel Tips
35 Useful Excel Tips35 Useful Excel Tips
35 Useful Excel Tips
 
Excel useful tips
Excel useful tipsExcel useful tips
Excel useful tips
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptx
 
Excel Tips
Excel TipsExcel Tips
Excel Tips
 
VBA
VBAVBA
VBA
 
Spreadsheets[1]
Spreadsheets[1]Spreadsheets[1]
Spreadsheets[1]
 
Excel Formulas Functions
Excel Formulas FunctionsExcel Formulas Functions
Excel Formulas Functions
 
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 Formulas Functions 2007
Excel Formulas Functions 2007Excel Formulas Functions 2007
Excel Formulas Functions 2007
 
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
 
SQL Views
SQL ViewsSQL Views
SQL Views
 

More from Brunel University

Ma3696 Lecture 0
Ma3696 Lecture 0Ma3696 Lecture 0
Ma3696 Lecture 0
Brunel University
 

More from Brunel University (8)

MA3696 Lecture 8
MA3696 Lecture 8MA3696 Lecture 8
MA3696 Lecture 8
 
MA3696 Lecture 7
MA3696 Lecture 7MA3696 Lecture 7
MA3696 Lecture 7
 
MA3696 Lecture 6
MA3696 Lecture 6MA3696 Lecture 6
MA3696 Lecture 6
 
MA3696 Lecture 5
MA3696 Lecture 5MA3696 Lecture 5
MA3696 Lecture 5
 
Ma3696 lecture 4
Ma3696 lecture 4Ma3696 lecture 4
Ma3696 lecture 4
 
Ma3696 Lecture 3
Ma3696 Lecture 3Ma3696 Lecture 3
Ma3696 Lecture 3
 
Ma3696 Lecture 2
Ma3696 Lecture 2Ma3696 Lecture 2
Ma3696 Lecture 2
 
Ma3696 Lecture 0
Ma3696 Lecture 0Ma3696 Lecture 0
Ma3696 Lecture 0
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

Ma3696 Lecture 1

  • 2. Important things to know in Excel The VBE environment A first go at some coding! SUMMARY
  • 4. CELL REFERENCES IN EXCEL Each cell has an ‘address’: “B5” Row 5, Column B. R5C2 Row 5, Column 2. R5 C2 B5
  • 5. CELL REFERENCES IN EXCEL Each cell has an ‘address’: “B5” Row 5, Column B. R5C2 Row 5, Column 2. Cells(5,2) Row 5, Column 2. Preferred notation within VBA because it can be looped. R5 C2 Cells(5,2)
  • 6.  A range can be: One cell (e.g., G2), or NAMING RANGES
  • 7.  A range can be: One cell (e.g., G2), or Multiple cells, which are next to each other (e.g., A2:E2) NAMING RANGES
  • 8.  What’s the benefit of naming ranges? If you move a named range:  The cell reference changes, but  The range name does not change  What’s that mean for you, the programmer? If you refer to a cell reference (e.g., G2), in your code, …and then move the contents of that cell …you have to go back and update your code If you refer to a named range (e.g., “PortfolioReturn”), in your code …and then move the contents of that cell (cut + paste) …you don’t have to update your code. NAMING RANGES
  • 9. A few rules… MUST start with a letter CANNOT contain any spaces CANNOT be the name of another range CANNOT be the name of the cell reference for another cell in Excel. NAMING RANGES “RET1” is already a cell in Excel so I can’t give another cell this name.
  • 10. 1. SAVE AS .xlsm 2. Save FREQUENTLY!! Excel crashes! 3. Saving your Excel workbook ALSO saves your VBA. 4. Use good files names so that you know which file is the newest version you’re working on. • Dissertation.xlsm • Disso.xlsm • myDisso.xlsm • DissoNew.xlsm • DissoNewest.xlsm SAVING YOUR WORK m for Macro Enabled • 13oct04Dissertation.xlsm • 2013oct04_Disso.xlsm • 04oct13_myDisso.xlsm
  • 12. GETTING FAMILIAR WITH THE VBE Alt + F11: Toggle between Excel and VBE, OR Go to the VBE from Excel Go back to Excel from the VBE
  • 13. GETTING FAMILIAR WITH THE VBE Excel File This is where you write your code
  • 14. GETTING FAMILIAR WITH THE VBE Code for data in Worksheets goes here Code in a specific sheet can only be executed for data and cells in that sheet. You CANNOT refer to cells in another worksheet or on a userform
  • 15. GETTING FAMILIAR WITH THE VBE Commands for the Workbook go here For example •Open the software when the workbook opens •Save the workbook when the software closes • Etc…
  • 16. GETTING FAMILIAR WITH THE VBE Code for Userforms go here Code which uses or refers to information obtained on the userform Code which executes when tools on the userform are used (e.g., command buttons)
  • 17. GETTING FAMILIAR WITH THE VBE Other code, not specific to any one userform or worksheet goes in a module For calculations, optimisation, or any code you want to be able to use at any time
  • 18.  Insert a Userform GETTING FAMILIAR WITH THE VBE
  • 19.  Insert a Userform  Insert a module GETTING FAMILIAR WITH THE VBE
  • 20.  Insert a Userform  Insert a module  Insert a procedure GETTING FAMILIAR WITH THE VBE We’ll come back to this later in the term
  • 21. INSERT A PROCEDURE You will use both Sub’s and Function’s during your FYP. We will discuss the difference later. The name should be descriptive of your Sub or Function. Cannot contain spaces. Click OK. This is what you should get: Write your code here. The Sub Procedure is now in the Module
  • 23. ACTIVATE A WORKBOOK Name of my workbook in “ ”. Tell VBA which workbook you want to work with
  • 24. ACTIVATE A WORKSHEET Tell VBA which worksheet you want to work with Name of my worksheet in “ ”.
  • 25. NAMING RANGES Use .Name Assign range names to… • One cell, or Must be in “ ” because it’s text!
  • 26. NAMING RANGES Use .Name Assign range names to… • One cell, or • A range of cells Must be in “ ” because it’s text!
  • 27. NAMING RANGES Assign range names to… • One cell, or • A range of cells Row 7, Column 1 (top left) Through to Row 9, Column 3 (btm right)
  • 28. ASSIGNING VALUES Enter a number into… • One cell, or • A range of cells InputBox(“ ”) Used to get input from the user
  • 29. ASSIGNING VALUES Enter text into… • One cell, or • A range of cells Text MUST be in “ ”
  • 30.  Check the range names by clicking on the cells  Did the code do what you thought it would? RUN THIS CODE (PRESS F5)
  • 31. USE EXCEL BUILT-IN FUNCTIONS FROM VBA Activate the correct worksheet
  • 32. USE EXCEL BUILT-IN FUNCTIONS FROM VBA Name the range where the numbers are in Excel
  • 33. USE EXCEL BUILT-IN FUNCTIONS FROM VBA Enter column headings
  • 34. USE EXCEL BUILT-IN FUNCTIONS FROM VBA Three ways to do the same thing Use what is best for the situation Enters the equation =Sum(numSeries) into Row 2, Col 3.
  • 35. USE EXCEL BUILT-IN FUNCTIONS FROM VBA Uses the built in Min function to find the minimum of the range named numSeries. Three ways to do the same thing Use what is best for the situation
  • 36. USE EXCEL BUILT-IN FUNCTIONS FROM VBA Uses the built in Max function to find the maximum of the range from Rows 1 to 7 in Col 1. Three ways to do the same thing Use what is best for the situation
  • 37.  In column 1 of your worksheet, create a list of 7 random numbers.  Insert a new Sub procedure called Exercise1.  Enter & run the following code: EXERCISE #1
  • 38.  From the Developer Tab: Choose Insert Under Form Controls, Select command Button  Draw a command button.  Select the macro you want to assign to this button. Only procedures in Modules will appear in the list. EXECUTING CODE USING FORM CONTROLS. Choose Exercise1
  • 39. Turn off Design Mode.  Make sure it is not highlighted  Your button now runs the code from the Sub Exercise1. Try changing your random numbers & re-running your code by using your button. EXECUTING CODE USING FORM CONTROLS.
  • 40. Create a Sub procedure called “Exercise2” Code the following in this sub: Activate your worksheet (use the sheet called ‘Example 3’) Assign a range name to the range of weights Assign a range name to the range of mean returns Assign a range name to cell G2, which will contain a formula for the portfolio return (next step) Assign equal weights into the weights range Enter the formula to calculate the portfolio return into G2 (use the SUMPRODUCT formula) Run your code (Put your cursor inside the sub & hit F5). Go back to Excel and make sure it’s correct. EXERCISE #2
  • 41. You are ready to move on when: LO1: You can name the address of a cell using Cells(r,c) or RC notation. LO2: In the VBE, you know the difference between adding code in a worksheet, a userform and a module. LO3: You can name ranges within Excel as well as name Excel ranges within VBA. LO4: You can assign numerical or text values to individual cells and ranges of cells from within VBA. LO5: You can describe the difference between the 3 ways of using Excel built-in functions within VBA. LEARNING OUTCOMES

Editor's Notes

  1. Show how to change excel to RC notation