VBA Programming Part One. Our Dartmouth Legacy 10 INPUT "What is your name: "; U$ 20 PRINT "Hello "; U$ 25 REM 30 INPUT "How many stars do you want: ";

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
EXCEL VBA 101 Current Status Waiting Using Excel/VBA to Speed-up Daily Data Processing An Introduction to VBA Yongjun Chen Click Me to Start …
Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
With Microsoft Excel 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2010.
Customisation The GUI in most GIS applications is sufficient for most needs. However, situations arise where you want either to: –Modify the interface,
How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
VBA Programming Session #2. Things to Review  Variables  Procedures: Subs & Functions  If…Then  For…Next.
Adding Automated Functionality to Office Applications.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
11 10/10/2005 BAE Spreadsheet Macros (Visual Basic for Applications) Slides to accompany an in-class demo of spreadsheet technique: Macro Programming.
© McGraw-Hill Companies, Inc., McGraw-Hill/Irwin Extended Learning Module M Programming in Excel with VBA.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
ChE 117 Motivation Lots of Tools Can’t always use “Canned Programs”
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Enhancing User Interaction Through Programming
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Chapter 11: Introduction to the Visual Basic Environment Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA 1 Lecture Outline Record macro and examine VBA code VBA Editor (IDE)
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
E0001 Computers in Engineering Procedures: subprograms and functions.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Visual Basic for Applications Macro Programming For Microsoft Office.
ME 142 Engineering Computation I Debugging Techniques.
Week 4.  Recap – Ranges  For Each Loops  Ranges Referencing Range Objects  Set (keyword)
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Chapter 3 The Visual Basic Editor. Important Features of the VBE Alt-F11 will open the Visual Basic Editor. The Code window is to the right, Project Explorer.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Chapter 9 Macros And Visual Basic For Applications.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
ME 142 Engineering Computation I Using Subroutines Effectively.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the.
ME 142 Engineering Computation I Using Subroutines Effectively.
Control Your Application Sequence, Selection, and Repetition.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Financial Information Management VB, VBA, VS, VSTO & VBE: Putting it all together Source: Excel VBA Programming by John Walkenbach.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
The Advantage Series ©2005 The McGraw-Hill Companies, Inc. All rights reserved Chapter 12 Introducing Visual Basic for Applications Microsoft Office Excel.
VBA - Excel VBA is Visual Basic for Applications
Spreadsheet-Based Decision Support Systems
Microsoft Access 2003 Illustrated Complete
Microsoft Access Illustrated
Microsoft Office Illustrated
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Introducing VBA Macros
Final Exam Review Part 4 - VBA
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Exploring Microsoft Excel
The structure of programming
Nate Brunelle Today: Conditional Decision Statements
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

VBA Programming Part One

Our Dartmouth Legacy 10 INPUT "What is your name: "; U$ 20 PRINT "Hello "; U$ 25 REM 30 INPUT "How many stars do you want: "; N 35 S$ = "" 40 FOR I = 1 TO N 50 S$ = S$ + "*" 55 NEXT I 60 PRINT S$ 65 REM

Startup Excel and hit… Alt-F11

First things first: Getting Help

Getting More Help

Project Explorer Excel objects User Forms Code Modules

Properties Window Properties are an object's characteristics, e.g. a sheet's name.

Immediate Window

Using the Immediate Window

Try the Immediate Window  MsgBox("Hello!")  x =  debug.Print x  'this is a comment  x = WorksheetFunction.Sum(1,2)  debug.Print x

Insert a module

Add some code Sub HelloWorld() MyName = InputBox("What is your name?") MsgBox ("Hi " + MyName) End Sub  Type "HelloWorld" in the Immediate Window to run your program.  Go back to Excel and run it from the Tools|Macro menu

Subroutines vs. Functions  Both are procedures: A named sequence of statements executed as a unit. (MS)  Functions return a value  Subroutines don't

Procedures take arguments

Arguments are variables

But what are variables?  "A named storage location that can contain data that can be modified during program execution." (MS) 1. Has name 2. Contains data 3. Can be modified

Convert Celsius to Fahrenheit Function Fahrenheit(Celsius) Fahrenheit = (Celsius * 1.8) + 32 End Function

Use the Function

Back to the Immediate Window x = 1 debug.Print x 1 x = 2 debug.Print x 2 'Set the value of x to 1 'Now set it to 2

Making Decisions

Decisions: If…Then Function VeryHot(Celsius) If (Celsius > 30) Then VeryHot = True Else VeryHot = False End If End Function

Which number is bigger? Function MyMax(x, y) If ( … ) Then … Else … End If End Function  Remember: 'FunctionName = Result'

Which number is bigger? (Solution) Function MyMax(x, y) If ( x > y ) Then MyMax = x Else MyMax = y End If End Function

Loops: For…Next For Variable = BeginValue to EndValue do something with Variable Next Sub firstLoop() For x = 1 To 10 Debug.Print x Next End Sub

Example: Sum of 1…N Function SumToN(N) SumToN = 0 For x = 1 To N SumToN = SumToN + x Next End Function

TemperatureChart  Create a sub called TemperatureChart  Use For…Next to loop Celsius from 0 to 40  Use debug.print to output the result of converting Celsius to Fahrenheit using our function

TemperatureChart (Solution) Sub TemperatureChart() For Celsius = 0 To 40 Debug.Print Fahrenheit(Celsius) Next End Sub

What we have covered so far…  The VBA environment  Inserting a module  Running a macro  Writing a user-defined function  Using the new function in Excel  Variables  If…Then…Else  For…Next