SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Excel training that “sticks” by 
Laura Winger
 Formulas 
 Formatting, Filtering and Finance 
 Sorting and Pivot Tables 
 Stats and Graphs 
 Access Basics 
 PowerPoint Tricks 
 Macro Basics 
 Syntax & Comments 
 Variables 
 If Statement & Reserved Words 
 Controls 
 Cells in Excel 
 Loops 
 Recording 
“It is when the tools of 
production are 
transparent, that we are 
inspired to create.” 
- Chris Anderson, 
The Long Tail 
Microsoft Excel Excellence 2
Macro Basics - Syntax 
• Visual Basic for Applications (VBA) 
– Syntax similar to Java and C++ 
– Example: 
If(oneValue = anotherValue) Then 
…… 
Else 
…… 
End If 
– As with formulas, you do not need to worry about 
capitalization. If you write “if”, when you go to another 
line of code, it will automatically correct itself it “If” 
Microsoft Excel Excellence 3
Macro Basics – Comments 
• Commenting is a good practice for ALL programmers, 
the more information, the better! 
• Use comments to describe sections of code and to 
make notes for yourself or other programmers 
• To write a comment, start with an apostrophe 
• The end of the line is the end of the comment, so if you 
need multiple lines of comments, each line must start 
with an apostrophe 
• A comment can be on its own line, or at the end of a 
line of code 
• Anything after the apostrophe is seen as a comment by 
the code 
'This macro was created on 4/1/2012 
'Created for Acme, Inc. 
'For help using this macro, please contact administrator. 
Microsoft Excel Excellence 4
Macro Basics - Variables 
• Variables are objects that store information 
– Can be set to be a string (text), integer, long (number with 
decimals), date, boolean (true or false) and much more… 
What kind of variable would you 
use to store… 
Variable type Reasoning 
a person’s name? String Names are not numbers 
or dates, they are text. 
a person’s age? Integer While you could say you 
are 35½, you generally 
give your age in whole 
numbers, so integer 
makes the most sense. 
a person’s birthday? Date (Duh?) 
a person’s hourly wage? Long Wages often have cents, 
so you would want to use 
long instead of integer. 
Microsoft Excel Excellence 5
Macro Basics - Variables 
• To declare a new variable name, start with the word “Dim” 
Dim newVar As String 
• Once you have a declared variable, you can give it values 
newVar = “Some text” 
– Note that this can be interpreted as “set variable newVar to be 
equal to ‘Some text’”. Setting values always go left to right. 
– Values for strings must be in quote marks, otherwise VBA 
will think it’s a variable or some code it doesn’t recognize. 
– Values for dates need to have pound signs around them 
Dim myDate As Date 
myDate = #1/14/2011# 
– Values for numbers (i.e. integers, long) can be entered 
without any punctuation 
Dim newVar1 As Integer 
Dim newVar2 As Long 
newVar1 = 42 
newVar2 = 37.9 
Microsoft Excel Excellence 6
Macro Basics - Variables 
• Let’s pretend we’re writing a macro about ages. 
Dim myName as String 
Dim myAge as Integer 
Dim myBirthday as Date 
myName = “Laura” 
myAge = 27 
myBirthday = 07/11/1984 
Like in formulas, capitalization 
does not matter in VBA 
programming!* 
*With one exception, which we’ll get into later. 
• Then we could write code that checks if today is my 
birthday, and if so, we would want to add 1 to my age. 
myAge = myAge + 1 
• But first, we’ll have to learn a few more tools… 
Microsoft Excel Excellence 7
Macro Basics – If Statement 
• If statements follow If, Then, Else format 
– Else is optional 
– Must end with an “End If” statement* 
*Unless done in one line 
If myAge > 20 Then 
allowedToDrink = True 
End If 
allowedToDrink = False 
If myAge If myAge > 20 Then > 20 Then allowedToDrink = True 
allowedToDrink = True 
Else 
allowedToDrink = False 
End If 
How are these different? 
 In Ex. 1, allowedToDrink has no value unless myAge is greater 
than 20, in which case it becomes True. 
 In Ex. 2, the default value is False, unless myAge is greater 
than 20, in which case it becomes True. 
 In Ex. 3, allowedToDrink gets a value either way. 
Microsoft Excel Excellence 8
Macro Basics – Reserved Words 
• Reserved words are special words that VBA has listed in its dictionary; 
these words alone cannot be declared or used as variables. 
• Date is not only a type of variable; it can be used in a formula to give 
you today’s date (based on the computer system’s date) 
myDate = Date + 1 'this gives you tomorrow’s date 
myDate = Date - 1 'this gives you yesterday’s date 
• Now gives you today’s date and the current time 
curTime = Now - Date 'this gives you the current time without the date 
• Time also gives you the current time 
• True and False are also reserved because they are the values of 
booleans 
Microsoft Excel Excellence 9
Macro Basics – If Statement 
– What is wrong with this code? 
Dim myName As String 
Dim myAge As Integer 
Dim myBirthday As Date 
myName = "Laura" 'note that quotes are used 
myAge = 27 
myBirthday = #7/11/1984# 'pound signs indicate a date 
If Date = myBirthday Then 
myAge = myAge + 1 'on my birthday, I will be a year older 
End If 
• Hint: What date is my next birthday? 
• Answer: It will never be 7/11/1984 again, so we need to 
transform myBirthday to be in the present year. 
Microsoft Excel Excellence 10
Macro Basics - Variables 
• Fixed code: 
Dim myName As String 
Dim myAge As Integer 
Dim myBirthday, curBirthday As Date 
myAge = 27 
myBirthday = #7/11/1984# 
curBirthday = DateSerial(Year(Date), _ 
Month(myBirthday), Day(myBirthday)) 
If Date = curBirthday Then 
myAge = myAge + 1 
End If 
Note that 
multiple 
variables of the 
same type can 
be declared in 
one line, just 
separate them 
with a comma 
and a space! 
Use an underscore 
to continue a line 
of code to the next 
line for easy 
reading. 
Microsoft Excel Excellence 11
Macro Basics - Variables 
• Review declaring variables 
– Syntax: Dim newVar as String 
• Declare variables as String, Integer, Date, Long, etc. 
– Can declare multiple variables of one type 
Dim newVar1, newVar2 as String 
• Why declare Variables? 
– Helps eliminate (or bring attention to) incorrect formats 
• For example, this will throw an error 
Dim myBirthday as Date 
myBirthday = “Laura” 
– Use capitalization to check your spelling 
• All my variables have at least one capital letter 
• When I type the variable, I write it with all lower case letters 
• If the variable is spelled correctly, it will capitalize automatically 
when I go to another line. 
• If variable is not declared, it will default to the last form typed 
Microsoft Excel Excellence 12
Macro Basics – Creating a Macro 
• Are you ready? In 
the View ribbon, go 
to Macros, and then 
View Macros 
• Type in a name for 
your macro (no 
spaces), and hit 
Create 
Microsoft Excel Excellence 13
Macro Basics - Variables 
• VBA creates a new macro for you called a “Sub”, and even puts 
the “End Sub” code at the bottom. In between, type this code: 
dim myName as string 
dim myAge as integer 
dim myBirthday, curBirthday, curDate as date 
myname = “Kevin” 'write your name, but don’t forget the quotes! 
myage = 27 'try putting in multiple spaces after the equals sign 
curdate = #1/15/12# 
mybirthday = #7/11/84# 'or use your own birthday here 
curbirthday = dateserial(year(date), month(mybirthday), day(mybirthday)) 
if curdate = curbirthday then 
myage = myage + 1 
end if 
Did VBA correct your capitalization? 
What did it do to your dates? 
Microsoft Excel Excellence 14
Congratulations! 
You just wrote your 
first VBA macro! 
Now take 
a break 
and 
celebrate!
Macro Basics – Controls 
• You can run the whole macro by hitting F5 on 
your keyboard or clicking the Run button 
• You can step into your macro by hitting F8 
• Put a Break into your macro by clicking in the 
gray area just left of the code. 
Microsoft Excel Excellence 16
Macro Basics – Controls 
• Try putting a break in your code on the 
beginning of the If statement. 
• Hit F5 or click the Run button 
• Take your cursor and hover over one of the 
variables. Does it have a value? 
Microsoft Excel Excellence 17
Macro Basics – Controls 
• Hit the Reset button 
• Change curDate to the date of your 
birthday, then run it again. 
• Hit F8 to step into the If statement 
• Hover over myAge – if the text is still 
highlighted in yellow, it hasn’t run that line 
of code yet 
• Hit F8 again 
• Now myAge should have increased! 
Microsoft Excel Excellence 18
Macro Basics – Controls 
• Click and drag the yellow arrow back up to 
the line above the If statement. 
• Hit F8 twice; myAge should have increased 
again. 
Microsoft Excel Excellence 19
Macro Basics – Cells in Excel 
• There are many ways to call cells, but for our purpose, 
we’re going to use just one 
• Syntax: Cells([row], [column]) 
• The row and column can be hard-coded or use variables 
• The Value of a cell is either the text, or if there’s a 
formula, what the formula evaluates to 
– Call the Value with this syntax: 
Cells([row], [column]).Value 
• You can set the Value of a cell like this: 
Cells([row], [column]).Value = 1 
• You can get the Value of a cell and store it in a variable: 
newVar1 = Cells([row], [column]).Value 
Microsoft Excel Excellence 20
Macro Basics – Cells in Excel 
• Identify and change values and formats of cells 
Cells([row], [column]).Activate 
ActiveCell.Value = “Hello” 
Range("A1:B2").Select 
– Selection.Interior.ColorIndex = 9 
– Cells([row], [column]).Interior.ColorIndex = 9 
Microsoft Excel Excellence 21
Macro Basics – User Input 
• Message Boxes can be used to alert the user of a critical issue, 
or to get boolean feedback from the user 
• Syntax: MsgBox([Prompt], [Buttons], [Title]...) 
• Only the Prompt is required, the rest are optional 
• The Prompt is the text you want displayed in the message box. 
• For a message: 
MsgBox("You have started a macro. Press OK to continue.") 
• To get feedback: 
myVariable = MsgBox("Are you well today?", vbYesNo) 
• Input Boxes are used to get data from the user 
• Syntax: InputBox([Prompt], [Title]...) 
• Again, only the Prompt is required 
• To get a value from the user: 
myAge = InputBox(“How old are you?”) 
Microsoft Excel Excellence 22
Macro Basics - Loops 
• Loops 
– For Loops increment an integer until it reaches a max 
value 
For i = 1 To 10 Step 2 
’(code inside for loop) 
Next i 
• The Step sets the interval i will increase by; this is optional, 
and if not set, will default to 1 
– While Loops continue to loop until a certain condition 
is met 
While i <= 10 
’ (code inside while loop) 
i = i + 2 
Wend 
These two sample codes essentially are 
equivalent, but we’ll show you examples 
that differentiate the two types of Loops. 
Microsoft Excel Excellence 23
Want more? 
Contact Laura Winger about Excel 
training that actually sticks!

Weitere ähnliche Inhalte

Was ist angesagt?

Excel Formula and Function Basics
Excel Formula and Function BasicsExcel Formula and Function Basics
Excel Formula and Function Basics
guest1c3d8c6
 

Was ist angesagt? (18)

27 Excel Hacks to Make You a Superstar
27 Excel Hacks to Make You a Superstar27 Excel Hacks to Make You a Superstar
27 Excel Hacks to Make You a Superstar
 
2016 ms excel_bm
2016 ms excel_bm2016 ms excel_bm
2016 ms excel_bm
 
Excel11
Excel11Excel11
Excel11
 
Excel Chapter 2
Excel Chapter 2Excel Chapter 2
Excel Chapter 2
 
Real World Excel Formulas
Real World Excel FormulasReal World Excel Formulas
Real World Excel Formulas
 
Data Analytics Using MS Excel
Data Analytics Using MS ExcelData Analytics Using MS Excel
Data Analytics Using MS Excel
 
Errors in ms excel
Errors in ms excelErrors in ms excel
Errors in ms excel
 
02 Excel entering data
02 Excel entering data02 Excel entering data
02 Excel entering data
 
Basic Formulas - Excel 2013 Tutorial
Basic Formulas - Excel 2013 TutorialBasic Formulas - Excel 2013 Tutorial
Basic Formulas - Excel 2013 Tutorial
 
Creating Formulas in Excel
Creating Formulas in ExcelCreating Formulas in Excel
Creating Formulas in Excel
 
Ms excel 2013 data management
Ms excel 2013 data managementMs excel 2013 data management
Ms excel 2013 data management
 
Office productivity tools
Office productivity toolsOffice productivity tools
Office productivity tools
 
Excel Formula and Function Basics
Excel Formula and Function BasicsExcel Formula and Function Basics
Excel Formula and Function Basics
 
Ms excel
Ms excelMs excel
Ms excel
 
95 exceltipsv4
95 exceltipsv495 exceltipsv4
95 exceltipsv4
 
Formulas and functions
Formulas and functions Formulas and functions
Formulas and functions
 
95 exceltipsv4
95 exceltipsv495 exceltipsv4
95 exceltipsv4
 
Chapter.05
Chapter.05Chapter.05
Chapter.05
 

Andere mochten auch

COMPASSION= GREAT CUSTOMER SERVICE (1)
COMPASSION= GREAT CUSTOMER SERVICE (1)COMPASSION= GREAT CUSTOMER SERVICE (1)
COMPASSION= GREAT CUSTOMER SERVICE (1)
Maya Hector
 
Management information system question and answers
Management information system question and answersManagement information system question and answers
Management information system question and answers
pradeep acharya
 
Microsoft Excel Project 1 Presentation
Microsoft Excel Project 1 PresentationMicrosoft Excel Project 1 Presentation
Microsoft Excel Project 1 Presentation
jmartinvvc
 
PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...
PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...
PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...
EPM Live
 
Management information system
Management information systemManagement information system
Management information system
Anamika Sonawane
 
Teaching Excel
Teaching ExcelTeaching Excel
Teaching Excel
sam ran
 

Andere mochten auch (17)

Winning PharmaSim Marketing Game Strategy
Winning PharmaSim Marketing Game StrategyWinning PharmaSim Marketing Game Strategy
Winning PharmaSim Marketing Game Strategy
 
Does Cisco have a John Chambers problem?
Does Cisco have a John Chambers problem?Does Cisco have a John Chambers problem?
Does Cisco have a John Chambers problem?
 
COMPASSION= GREAT CUSTOMER SERVICE (1)
COMPASSION= GREAT CUSTOMER SERVICE (1)COMPASSION= GREAT CUSTOMER SERVICE (1)
COMPASSION= GREAT CUSTOMER SERVICE (1)
 
IT Project Portfolio Planning Using Excel
IT Project Portfolio Planning Using ExcelIT Project Portfolio Planning Using Excel
IT Project Portfolio Planning Using Excel
 
Entering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 TutorialEntering Data - Excel 2013 Tutorial
Entering Data - Excel 2013 Tutorial
 
Management information system question and answers
Management information system question and answersManagement information system question and answers
Management information system question and answers
 
Microsoft Excel Project 1 Presentation
Microsoft Excel Project 1 PresentationMicrosoft Excel Project 1 Presentation
Microsoft Excel Project 1 Presentation
 
Worksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 TutorialWorksheet Basics & Navigation - Excel 2013 Tutorial
Worksheet Basics & Navigation - Excel 2013 Tutorial
 
Basic Functions - Excel 2013 Tutorial
Basic Functions - Excel 2013 TutorialBasic Functions - Excel 2013 Tutorial
Basic Functions - Excel 2013 Tutorial
 
PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...
PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...
PPM Challenge #4: Improving PPM Maturity – 2012 PPM Challenge and Opportunity...
 
MIS Presentation
MIS PresentationMIS Presentation
MIS Presentation
 
Management information system
Management information systemManagement information system
Management information system
 
Detergent Market in India as of 2015 (Surf Excel, Ariel, Nirma, Wheel, Tide, ...
Detergent Market in India as of 2015 (Surf Excel, Ariel, Nirma, Wheel, Tide, ...Detergent Market in India as of 2015 (Surf Excel, Ariel, Nirma, Wheel, Tide, ...
Detergent Market in India as of 2015 (Surf Excel, Ariel, Nirma, Wheel, Tide, ...
 
Teaching Excel
Teaching ExcelTeaching Excel
Teaching Excel
 
Management Information System (MIS)
Management Information System (MIS)Management Information System (MIS)
Management Information System (MIS)
 
Introduction to Excel - Excel 2013 Tutorial
Introduction to Excel - Excel 2013 TutorialIntroduction to Excel - Excel 2013 Tutorial
Introduction to Excel - Excel 2013 Tutorial
 
MS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATIONMS EXCEL PPT PRESENTATION
MS EXCEL PPT PRESENTATION
 

Ähnlich wie Excel Excellence (Microsoft Excel training that "sticks"): Macros

Excel basics for everyday use part two
Excel basics for everyday use part twoExcel basics for everyday use part two
Excel basics for everyday use part two
Kevin McLogan
 
WK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docx
WK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docxWK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docx
WK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docx
ambersalomon88660
 

Ähnlich wie Excel Excellence (Microsoft Excel training that "sticks"): Macros (20)

Excel basics for everyday use-the more advanced stuff
Excel basics for everyday use-the more advanced stuffExcel basics for everyday use-the more advanced stuff
Excel basics for everyday use-the more advanced stuff
 
Excel for SEO -from Distilled UK
Excel for SEO -from Distilled UKExcel for SEO -from Distilled UK
Excel for SEO -from Distilled UK
 
Empowerment Technologies - Module 5
Empowerment Technologies - Module 5Empowerment Technologies - Module 5
Empowerment Technologies - Module 5
 
Excel basics for everyday use part two
Excel basics for everyday use part twoExcel basics for everyday use part two
Excel basics for everyday use part two
 
CBN Advanced Excel Training Slide.pptx
CBN Advanced Excel Training Slide.pptxCBN Advanced Excel Training Slide.pptx
CBN Advanced Excel Training Slide.pptx
 
Excel intermediate
Excel intermediateExcel intermediate
Excel intermediate
 
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
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
De vry math 399 all ilabs latest 2016 november
De vry math 399 all ilabs latest 2016 novemberDe vry math 399 all ilabs latest 2016 november
De vry math 399 all ilabs latest 2016 november
 
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
 
WK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docx
WK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docxWK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docx
WK8_A2 OverviewAssignment 2 Excelling with ExcelDue Week 8 an.docx
 
Cte handout for ict2
Cte handout for ict2Cte handout for ict2
Cte handout for ict2
 
Learn Excel Macro
Learn Excel Macro  Learn Excel Macro
Learn Excel Macro
 
Lesson 6.pptx
Lesson 6.pptxLesson 6.pptx
Lesson 6.pptx
 
Elementary Data Analysis with MS Excel_Day-2
Elementary Data Analysis with MS Excel_Day-2Elementary Data Analysis with MS Excel_Day-2
Elementary Data Analysis with MS Excel_Day-2
 
Advanced Models
Advanced ModelsAdvanced Models
Advanced Models
 
Vba part 1
Vba part 1Vba part 1
Vba part 1
 
Spreadsheets for developers
Spreadsheets for developersSpreadsheets for developers
Spreadsheets for developers
 
De vry math 221 all discussion+ilbs latest 2016 november
De vry math 221 all discussion+ilbs latest 2016 novemberDe vry math 221 all discussion+ilbs latest 2016 november
De vry math 221 all discussion+ilbs latest 2016 november
 
Advanced Microsoft Excel Training
Advanced Microsoft Excel TrainingAdvanced Microsoft Excel Training
Advanced Microsoft Excel Training
 

Kürzlich hochgeladen

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
dollysharma2066
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
Abortion pills in Kuwait Cytotec pills in Kuwait
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
Renandantas16
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 

Kürzlich hochgeladen (20)

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLBAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
BAGALUR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 

Excel Excellence (Microsoft Excel training that "sticks"): Macros

  • 1. Excel training that “sticks” by Laura Winger
  • 2.  Formulas  Formatting, Filtering and Finance  Sorting and Pivot Tables  Stats and Graphs  Access Basics  PowerPoint Tricks  Macro Basics  Syntax & Comments  Variables  If Statement & Reserved Words  Controls  Cells in Excel  Loops  Recording “It is when the tools of production are transparent, that we are inspired to create.” - Chris Anderson, The Long Tail Microsoft Excel Excellence 2
  • 3. Macro Basics - Syntax • Visual Basic for Applications (VBA) – Syntax similar to Java and C++ – Example: If(oneValue = anotherValue) Then …… Else …… End If – As with formulas, you do not need to worry about capitalization. If you write “if”, when you go to another line of code, it will automatically correct itself it “If” Microsoft Excel Excellence 3
  • 4. Macro Basics – Comments • Commenting is a good practice for ALL programmers, the more information, the better! • Use comments to describe sections of code and to make notes for yourself or other programmers • To write a comment, start with an apostrophe • The end of the line is the end of the comment, so if you need multiple lines of comments, each line must start with an apostrophe • A comment can be on its own line, or at the end of a line of code • Anything after the apostrophe is seen as a comment by the code 'This macro was created on 4/1/2012 'Created for Acme, Inc. 'For help using this macro, please contact administrator. Microsoft Excel Excellence 4
  • 5. Macro Basics - Variables • Variables are objects that store information – Can be set to be a string (text), integer, long (number with decimals), date, boolean (true or false) and much more… What kind of variable would you use to store… Variable type Reasoning a person’s name? String Names are not numbers or dates, they are text. a person’s age? Integer While you could say you are 35½, you generally give your age in whole numbers, so integer makes the most sense. a person’s birthday? Date (Duh?) a person’s hourly wage? Long Wages often have cents, so you would want to use long instead of integer. Microsoft Excel Excellence 5
  • 6. Macro Basics - Variables • To declare a new variable name, start with the word “Dim” Dim newVar As String • Once you have a declared variable, you can give it values newVar = “Some text” – Note that this can be interpreted as “set variable newVar to be equal to ‘Some text’”. Setting values always go left to right. – Values for strings must be in quote marks, otherwise VBA will think it’s a variable or some code it doesn’t recognize. – Values for dates need to have pound signs around them Dim myDate As Date myDate = #1/14/2011# – Values for numbers (i.e. integers, long) can be entered without any punctuation Dim newVar1 As Integer Dim newVar2 As Long newVar1 = 42 newVar2 = 37.9 Microsoft Excel Excellence 6
  • 7. Macro Basics - Variables • Let’s pretend we’re writing a macro about ages. Dim myName as String Dim myAge as Integer Dim myBirthday as Date myName = “Laura” myAge = 27 myBirthday = 07/11/1984 Like in formulas, capitalization does not matter in VBA programming!* *With one exception, which we’ll get into later. • Then we could write code that checks if today is my birthday, and if so, we would want to add 1 to my age. myAge = myAge + 1 • But first, we’ll have to learn a few more tools… Microsoft Excel Excellence 7
  • 8. Macro Basics – If Statement • If statements follow If, Then, Else format – Else is optional – Must end with an “End If” statement* *Unless done in one line If myAge > 20 Then allowedToDrink = True End If allowedToDrink = False If myAge If myAge > 20 Then > 20 Then allowedToDrink = True allowedToDrink = True Else allowedToDrink = False End If How are these different?  In Ex. 1, allowedToDrink has no value unless myAge is greater than 20, in which case it becomes True.  In Ex. 2, the default value is False, unless myAge is greater than 20, in which case it becomes True.  In Ex. 3, allowedToDrink gets a value either way. Microsoft Excel Excellence 8
  • 9. Macro Basics – Reserved Words • Reserved words are special words that VBA has listed in its dictionary; these words alone cannot be declared or used as variables. • Date is not only a type of variable; it can be used in a formula to give you today’s date (based on the computer system’s date) myDate = Date + 1 'this gives you tomorrow’s date myDate = Date - 1 'this gives you yesterday’s date • Now gives you today’s date and the current time curTime = Now - Date 'this gives you the current time without the date • Time also gives you the current time • True and False are also reserved because they are the values of booleans Microsoft Excel Excellence 9
  • 10. Macro Basics – If Statement – What is wrong with this code? Dim myName As String Dim myAge As Integer Dim myBirthday As Date myName = "Laura" 'note that quotes are used myAge = 27 myBirthday = #7/11/1984# 'pound signs indicate a date If Date = myBirthday Then myAge = myAge + 1 'on my birthday, I will be a year older End If • Hint: What date is my next birthday? • Answer: It will never be 7/11/1984 again, so we need to transform myBirthday to be in the present year. Microsoft Excel Excellence 10
  • 11. Macro Basics - Variables • Fixed code: Dim myName As String Dim myAge As Integer Dim myBirthday, curBirthday As Date myAge = 27 myBirthday = #7/11/1984# curBirthday = DateSerial(Year(Date), _ Month(myBirthday), Day(myBirthday)) If Date = curBirthday Then myAge = myAge + 1 End If Note that multiple variables of the same type can be declared in one line, just separate them with a comma and a space! Use an underscore to continue a line of code to the next line for easy reading. Microsoft Excel Excellence 11
  • 12. Macro Basics - Variables • Review declaring variables – Syntax: Dim newVar as String • Declare variables as String, Integer, Date, Long, etc. – Can declare multiple variables of one type Dim newVar1, newVar2 as String • Why declare Variables? – Helps eliminate (or bring attention to) incorrect formats • For example, this will throw an error Dim myBirthday as Date myBirthday = “Laura” – Use capitalization to check your spelling • All my variables have at least one capital letter • When I type the variable, I write it with all lower case letters • If the variable is spelled correctly, it will capitalize automatically when I go to another line. • If variable is not declared, it will default to the last form typed Microsoft Excel Excellence 12
  • 13. Macro Basics – Creating a Macro • Are you ready? In the View ribbon, go to Macros, and then View Macros • Type in a name for your macro (no spaces), and hit Create Microsoft Excel Excellence 13
  • 14. Macro Basics - Variables • VBA creates a new macro for you called a “Sub”, and even puts the “End Sub” code at the bottom. In between, type this code: dim myName as string dim myAge as integer dim myBirthday, curBirthday, curDate as date myname = “Kevin” 'write your name, but don’t forget the quotes! myage = 27 'try putting in multiple spaces after the equals sign curdate = #1/15/12# mybirthday = #7/11/84# 'or use your own birthday here curbirthday = dateserial(year(date), month(mybirthday), day(mybirthday)) if curdate = curbirthday then myage = myage + 1 end if Did VBA correct your capitalization? What did it do to your dates? Microsoft Excel Excellence 14
  • 15. Congratulations! You just wrote your first VBA macro! Now take a break and celebrate!
  • 16. Macro Basics – Controls • You can run the whole macro by hitting F5 on your keyboard or clicking the Run button • You can step into your macro by hitting F8 • Put a Break into your macro by clicking in the gray area just left of the code. Microsoft Excel Excellence 16
  • 17. Macro Basics – Controls • Try putting a break in your code on the beginning of the If statement. • Hit F5 or click the Run button • Take your cursor and hover over one of the variables. Does it have a value? Microsoft Excel Excellence 17
  • 18. Macro Basics – Controls • Hit the Reset button • Change curDate to the date of your birthday, then run it again. • Hit F8 to step into the If statement • Hover over myAge – if the text is still highlighted in yellow, it hasn’t run that line of code yet • Hit F8 again • Now myAge should have increased! Microsoft Excel Excellence 18
  • 19. Macro Basics – Controls • Click and drag the yellow arrow back up to the line above the If statement. • Hit F8 twice; myAge should have increased again. Microsoft Excel Excellence 19
  • 20. Macro Basics – Cells in Excel • There are many ways to call cells, but for our purpose, we’re going to use just one • Syntax: Cells([row], [column]) • The row and column can be hard-coded or use variables • The Value of a cell is either the text, or if there’s a formula, what the formula evaluates to – Call the Value with this syntax: Cells([row], [column]).Value • You can set the Value of a cell like this: Cells([row], [column]).Value = 1 • You can get the Value of a cell and store it in a variable: newVar1 = Cells([row], [column]).Value Microsoft Excel Excellence 20
  • 21. Macro Basics – Cells in Excel • Identify and change values and formats of cells Cells([row], [column]).Activate ActiveCell.Value = “Hello” Range("A1:B2").Select – Selection.Interior.ColorIndex = 9 – Cells([row], [column]).Interior.ColorIndex = 9 Microsoft Excel Excellence 21
  • 22. Macro Basics – User Input • Message Boxes can be used to alert the user of a critical issue, or to get boolean feedback from the user • Syntax: MsgBox([Prompt], [Buttons], [Title]...) • Only the Prompt is required, the rest are optional • The Prompt is the text you want displayed in the message box. • For a message: MsgBox("You have started a macro. Press OK to continue.") • To get feedback: myVariable = MsgBox("Are you well today?", vbYesNo) • Input Boxes are used to get data from the user • Syntax: InputBox([Prompt], [Title]...) • Again, only the Prompt is required • To get a value from the user: myAge = InputBox(“How old are you?”) Microsoft Excel Excellence 22
  • 23. Macro Basics - Loops • Loops – For Loops increment an integer until it reaches a max value For i = 1 To 10 Step 2 ’(code inside for loop) Next i • The Step sets the interval i will increase by; this is optional, and if not set, will default to 1 – While Loops continue to loop until a certain condition is met While i <= 10 ’ (code inside while loop) i = i + 2 Wend These two sample codes essentially are equivalent, but we’ll show you examples that differentiate the two types of Loops. Microsoft Excel Excellence 23
  • 24. Want more? Contact Laura Winger about Excel training that actually sticks!

Hinweis der Redaktion

  1. Add waterfall charts? (i.e. OverMax 17 week segmentation)