VBA Programming Functions and Decisions. If-Then-Else Structure used to consider alternatives If then --or-- If then Else End If.

Slides:



Advertisements
Similar presentations
“Going loopy with Visual Basic!”
Advertisements

1 Overview Introduction to VBA The Visual Basic Editor (VBE) –First Program Getting Started with VBA –Subroutines –Declaring variables –Input boxes and.
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
Selection (decision) control structure Learning objective
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
String Variables Visual Basic for Applications 4.
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
Control Statements Making Decision in Your Program.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Creating Embedded Formative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
# 1# 1 VBA Objects, Message Boxes as Functions What is an object in VBA? How do you move between design mode and run mode? How can you make a cell become.
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA 1 Lecture Outline Record macro and examine VBA code VBA Editor (IDE)
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
Visual Basic for Applications Macro Programming For Microsoft Office.
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-2 1 Lecture Outline Mathematical Expressions String Concatenation Built-in.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
CHAPTER FIVE Specifying Alternate Courses of Action: Selection Statements.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Dialog Boxes – Day 1 Built-in Dialog Boxes Input Box Message Box Custom Dialog Boxes – User Forms.
Basics 2. Write a macro that … … uses a popup message box to say Hello. (msgbox ”Hello”) … writes the contents of the active cell in a message box. (you.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Chapter 9 Macros And Visual Basic For Applications.
Introduction to Computer Programming
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
OV Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
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 Input, Output & Documentation.
A Macro to Exchange the Values of Arbitrary Cells.
VBA Navigation, Conditionals, and Boxes. VBA Navigation.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
Controlling Program Flow with Looping Structures
Using Control Structures. Goals Understand the three basic forms of control structures Understand how to create and manage conditionals Understand how.
Controlling Program Flow with Decision Structures.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
ME 142 Engineering Computation I Interacting with Spreadsheets.
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
Custom Dialog Box Alternatives And Dealing with FileNames Joanna Wyrobek.
Chapter 6 Controlling Program Flow with Looping Structures.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
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.
© 2006 Lawrenceville Press Slide 1 Chapter 5 The If…Then Statement (One-Way)  Conditional control structure, also called a decision structure  Executes.
CIS 338: Dialog Boxes Dr. Ralph D. Westfall April, 2011.
Access VBA Programming for Beginners - Class 3 -
Chapter 4 The If…Then Statement
Visual Basic I Programming
Exploring Microsoft Excel
VBScript Session 6 Dani Vainstein.
المحاضرة السادسة.
Program Flow.
Chapter 3: Selection Structures: Making Decisions
More on If statements (Calculate, Calculate1, Calculate2)
Presentation transcript:

VBA Programming Functions and Decisions

If-Then-Else Structure used to consider alternatives If then --or-- If then Else End If

If-Then Decision Flow Flow chart branches forward Code: vName = Inputbox(…) If vName = “” then vName = Inputbox(…) End If Range(“B3”) = vName Start Get user name Is name empty? Write name to cell B3 End Get user name Yes No

If-Then-Else Structure Selects one of two choices Code If [B3].value < 0 then [B3].font.colorindex = 3 Else [B3].font.colorindex = 41 End If Is value negative? Set text color to black Yes No Set text color to red

If-Then-Else Example

MsgBox Function MsgBox(Prompt, Buttons, Title) Buttons is a number telling VBA which buttons to show MsgBox(“Is it raining?”, 4, “Raining”) yields:

MsgBox Function How do you know the button numbers? Use Help to find them Use built-in constants MsgBox(“Is it raining?”, vbYesNo) VBA finds that vbYesNo = 4 Results are the same Returns a number Yes = 6 (vbYes) No = 7 (vbNo) The MsgBox function cannot appear by itself.

MsgBox Function Example Include in an assignment statement Use “If-Then” to take action: vAnswer = MsgBox(“Is it raining?”, vbYesNo) If vAnswer = vbYes then vOut = “Help, its raining!” Else vOut = “OK, its dry!” End if MsgBox vOut