1 Overview Introduction to VBA The Visual Basic Editor (VBE) –First Program Getting Started with VBA –Subroutines –Declaring variables –Input boxes and.

Slides:



Advertisements
Similar presentations
Sep-05 Slide:1 VBA in Excel Walter Milner. Sep-05 Slide:2 VBA in Excel Introduction VBA = Visual Basic for Applications Enables end-user programming In.
Advertisements

Lists, Loops, Validation, and More
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
1 After completing this lesson, you will be able to: Create a database. Create a table using the Table Wizard. Create and modify a table in Design view.
INTRODUCTORY MICROSOFT ACCESS Lesson 1 – Access Basics
Information System Design Lab 5&6. User Interface Design.
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Using VB with MS Applications R. Juhl, Delta College.
Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
15-18, 2003 Lab 4 Introduction to VBA (I) ► Excel Object Model ► VBA Basics ► Exercise.
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
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA By Robert T. Grauer Maryann Barber.
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Using the Visual Basic Editor Visual Basic for Applications 1.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Week 1.  Kate Watson  Checked at least every other day. Queries and general comments welcome.
Lab 9 – User Forms Design. User Forms What are user forms? –Known as dialog boxes –Major ways for getting user input An example of using user forms: Monthly.
VBA – Visual Basic for Applications Week 20 - Tutorial.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
Project 9 Using Visual Basic for Applications (VBA) to Customize and Automate Excel Jason C. H. Chen, Ph.D. Professor of Management Information Systems.
© 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.
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.
# 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 to Engineering Computing GEEN 1300 Lecture 7 15 June 2010 Review for midterm.
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Introduction to VBA MGMI Aug What is VBA? VBA = Visual Basic for Application Excel’s powerful built-in programming language An event-driven.
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.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Lab 01 Forms in excel Tahani ALdweesh Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’
Visual Basic for Applications Macro Programming For Microsoft Office.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
OCC Network Drives  H:\  P:\ 
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
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.
Exploring Microsoft Access Chapter 8 Creating More Powerful Applications: Introduction to VBA.
Chapter 9 Macros And Visual Basic For Applications.
Vocabulary in VB So Far. Assignment: Used to change the value of an object at run time Used to change the value of an object at run time.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
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.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
Visual Basic. The Close Method The Close method is used to close a form. To close a form use the keyword Me to refer to the form. Me.Close()
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
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.
IE 8580 Module 4: DIY Monte Carlo Simulation
Microsoft Office Illustrated
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Introduction to VBA IE 469 Spring 2018.
VISUAL BASIC.
Exploring Microsoft Excel
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

1 Overview Introduction to VBA The Visual Basic Editor (VBE) –First Program Getting Started with VBA –Subroutines –Declaring variables –Input boxes and Message boxes –With construction

2 Introduction to the VBA VBA, Visual Basic for Applications, is an implementation of Microsoft's Visual Basic, an event driven programming language and associated integrated development environment (IDE) which is built into most Microsoft Office applications. However, VBA and VB are not the same. –Similar in programming elements –VBA is the language to manipulate Excel (and other applications).

3 Visual Basic Editor Visual Basic Editor (VBE) is the Integrated Development Environment (IDE) for programming with VBA. It can be accessed by pressing [Alt] + [F11] Code window Project explorer, Properties window, (just like IDE for VB.Net)

4 VBE

5 First Program Open “FirstProgram.xls” downloaded from Web site.FirstProgram.xls Press [Alt] + [F11]

6 FirstProgram (cont.) Insert a module to the project Start typing Sub CountHighSales and hit [Enter] You will see a Subroutine block is inserted automatically.

7 FirstProgram (cont.) Type the rest of the syntax in the module: Dim i As Integer Dim j As Integer Dim numberHigh As Integer Dim salesCutoff As Currency salesCutoff = InputBox("What sales value do you want to check for?") For j = 1 To 6 numberHigh = 0 For i = 1 To 36 If Range("SalesRange").Cells(i, j) >= salesCutoff Then _ numberHigh = numberHigh + 1 Next i MsgBox "For region " & j & ", sales were above " & _ Format(salesCutoff, "$0,000") & " on " & numberHigh & " of the 36 months." Next j

8 FirstProgram (cont.) Run the program from the VBE Run -> Run Sub/USerForm F5 or Type in a number in the InputBox, such as

9 FirstProgram (cont.) Run the program with a button –Right click tool bar and choose “Form” tool bar –Drag button form in somewhere on the right side of the data –Choose the macro you just created –Change the name as appropriate

10 Subroutines Sub CountHighSales() End Sub

11 Declaring variables Dim i As Integer Dim j As Integer Dim numberHigh As Integer Dim salesCutoff As Currency Option Explicit – need to declare variables before you can use it

12 Input boxes and Message boxes InputBox(“prompt”, “title”) – returns user’s input as data MsgBox “Prompt”, type, “title” –vbInformation – information display –vbYesNo – display information and Yes and No buttons; returns vbYes or vbNo – vbExplanation, etc. Require parentheses if the box captures the result (input or yes/no answer)

13 With construction Properties are described top down, separated by “.” (period) e.g., Workboolks(“Sales”).Woksheets(“March”).Range(“A1”).Value Workboolks(“Sales”).Woksheets(“March”).Range(“A1”).Font.Name Workboolks(“Sales”).Woksheets(“March”).Range(“A1”).Font.Size Using “With” key word, it may be structured without repeating the same. With Workboolks(“Sales”).Woksheets(“March”).Range(“A1”).Value = “Sales for march” With.Font.Name = “Times New Roman”.Size = 14

14 Exercise The file ExamScores.xls contains scores for an exam in the range A1:A100.ExamScores.xls Write a program that reports the average, standard deviation, minimum, and maximum of the scores in a message box. Range is set in a module already. Use Excel’s functions (with Application.WorksheetFunction. )