Excel & Visual Basic for Applications (VBA)

Similar documents
6/14/2010. VBA program units: Subroutines and Functions. Functions: Examples: Examples:

Understanding the MsgBox command in Visual Basic

Programming Concepts and Skills. Arrays continued and Functions

MICROSOFT EXCEL 2000 LEVEL 5 VBA PROGRAMMING INTRODUCTION

variables programming statements

An InputBox( ) function will display an input Box window where the user can enter a value or a text. The format is

IFA/QFN VBA Tutorial Notes prepared by Keith Wong

3 IN THIS CHAPTER. Understanding Program Variables

MICROSOFT EXCEL VISUAL BASIC FOR APPLICATIONS INTERMEDIATE

Contents. Some Basics Simple VBA Procedure (Macro) To Execute The Procedure Recording A Macro About Macro Recorder VBA Objects Reference

Creating Macros David Giusto, Technical Services Specialist, Synergy Resources

VBA. VBA at a glance. Lecture 61

Alternatives To Custom Dialog Box

Programming with visual Basic:

Customizing the Excel 2013 program window. Getting started with Excel 2013

This chapter is intended to take you through the basic steps of using the Visual Basic

Excel VBA Programming

Excel for Engineers Part 2

Introduction... 1 Part I: Getting Started with Excel VBA Programming Part II: How VBA Works with Excel... 31

Excel Macro Record and VBA Editor. Presented by Wayne Wilmeth

ENGG1811 Computing for Engineers Week 9 Dialogues and Forms Numerical Integration

INFORMATICS: Computer Hardware and Programming in Visual Basic 81

MS Excel VBA Class Goals

I

Unit 9 Spreadsheet development. Create a user form

2. create the workbook file

MgtOp 470 Business Modeling with Spreadsheets Sample Midterm Exam. 1. Spreadsheets are known as the of business analysis.

Visual Programming 1. What is Visual Basic? 2. What are different Editions available in VB? 3. List the various features of VB

BASIC EXCEL SYLLABUS Section 1: Getting Started Section 2: Working with Worksheet Section 3: Administration Section 4: Data Handling & Manipulation

IFA/QFN VBA Tutorial Notes prepared by Keith Wong

Agenda. First Example 24/09/2009 INTRODUCTION TO VBA PROGRAMMING. First Example. The world s simplest calculator...

3. (1.0 point) To quickly switch to the Visual Basic Editor, press on your keyboard. a. Esc + F1 b. Ctrl + F7 c. Alt + F11 d.

Microsoft Office Excel 2007: Basic Course 01 - Getting Started

Excel Programming with VBA (Macro Programming) 24 hours Getting Started

Extending the Unit Converter

VISUAL BASIC 2 EDITOR

Corporate essentials

Microsoft Excel 2010 Level 1

Delivering training since 1996

Excel 2016: Introduction to VBA

Create an external reference (link) to a cell range in another workbook

Download the files from you will use these files to finish the following exercises.

Reference Services Division Presents. Excel Introductory Course

Microsoft Excel 2016 Level 1

download instant at

Ms Excel Vba Continue Loop Through Worksheets By Name

You can record macros to automate tedious

Lookup Project. frmlookup (Name: object is a combo box, style 2); use 4 labels: 2 for phone, 2 for mail. MsgBox Function:

Introduction to macros

Instruction How To Use Excel 2007 Macros >>>CLICK HERE<<<

Lab Manual Visual Basic 6.0

Excel 2010 Macro Vba For Loops Break Nested

Starting Excel application

The American University in Cairo. Academic Computing Services. Excel prepared by. Maha Amer

Reviewing Hidden Content during Native Review

Acknowledgements About the Author Starting off on the Right Foot p. 1 Basic Terminology p. 2 Title Bar p. 3 Menu Bar p. 3 Active Cell p.

As an A+ Certified Professional, you will want to use the full range of

Workbooks (File) and Worksheet Handling

Microsoft Excel 2007

BASIC MACROINSTRUCTIONS (MACROS)

Use Do Until to break links

Computer Applications Data Processing FA 14

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

Validate and Protect Data

Excel & Business Math Video/Class Project #28 IF Function, ISBLANK function and Building a Check Register

Lesson 1: Exploring Excel Return to the FastCourse Excel 2007 Level 1 book page

Ms excel. The Microsoft Office Button. The Quick Access Toolbar

Rev Up to Excel 2010

Getting started 7. Writing macros 23

Excel Vba Manually Update Links Automatically On Open Workbook Don

Read More: Index Function Excel [Examples, Make Dynamic Range, INDEX MATCH]

MS Exceli automatiseerimine makrode abil

Changing Case using Worksheet Functions and Excel VBA

University of North Dakota PeopleSoft Finance Tip Sheets. Utilizing the Query Download Feature

Microsoft Excel Chapter 1. Creating a Worksheet and a Chart

Formatting Spreadsheets in Microsoft Excel

Microsoft Excel > Shortcut Keys > Shortcuts

COMPUTERIZED OFFICE SUPPORT PROGRAM

Pivot Tables and Pivot Charts Activities

Table of Contents. Contents

Candy is Dandy Project (Project #12)

Excel Tools Features... 1 Comments... 2 List Comments Formatting... 3 Center Across... 3 Hide Blank Rows... 3 Lists... 3 Sheet Links...

Microsoft Excel 2007

Read Me First (Excel 2007)

Create a Relationship to build a Pivot Table

IITS Workshop Creating a Gradebook in Microsoft Office Excel 2007

Microsoft Excel - Macros Explained

Contents. Group 2 Excel Handouts 2010

Pivot Tables, Lookup Tables and Scenarios

A casual approach to numerical modeling

Working with Excel CHAPTER 1

Excel. More Skills 11 Insert and Edit Comments. To complete this workbook, you will need the following file: You will save your workbook as: CHAPTER 2

VBA Collections A Group of Similar Objects that Share Common Properties, Methods and

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

WEEK NO. 12 MICROSOFT EXCEL 2007

Office of Instructional Technology

User Guide. Version 2.0. Excel Spreadsheet to AutoCAD drawing Utility. Supports AutoCAD 2000 through Supports Excel 97, 2000, XP, 2003, 2007

Skills Exam Objective Objective Number

Introduction to Microsoft Excel

Abdulbasit H. Mhdi Assistant lecturer Chemical engineering/ Tikrit University

Transcription:

Class meeting #18 Monday, Oct. 26 th GEEN 1300 Introduction to Engineering Computing Excel & Visual Basic for Applications (VBA) user interfaces o on-sheet buttons o InputBox and MsgBox functions o userforms Homework #8, due Wednesday, Nov. 11 th This is a double-weighted project assignment Section Test 2, next Monday, Nov. 2 nd, 7-9 p.m., same rooms Coverage: Classes 10-18, Labs 6-9, Text chaps 7-141 On-Sheet Buttons 1) use the Forms toolbar to place a button on the worksheet 2) assign a macro to the button 3) format the button as desired Developer tab Insert Form Controls 2 1

On-Sheet Buttons draw button on worksheet and Assign Macro dialog appears automatically select macro for button and click OK change button text 3 On-Sheet Buttons change font style 4 2

On-Sheet Buttons click button to run macro use on-sheet buttons for macros dedicated di d to the workbook and worksheet, often to launch userforms 5 InputBox Function simplified version InputBox( prompt, title, default value ) optional typical use Xin = InputBox( Enter value for x: ) [ assign result of InputBox to variable for later use ] complete version InputBox( prompt, title,default,xpos,ypos,helpfile,context) optional 6 3

InputBox Method (alternative to InputBox Function) object.inputbox( prompt, title, default, xpos, ypos, helpfile, context, type) type codes 0 formula 1 number 2 string 4 logical 8 cell reference 16 error value, e.g., #N/A 64 array of values optional codes can be combined to allow for inputs of multiple types, e.g., 3 for number or string 7 InputBox Method (alternative to InputBox Function) 8 4

MsgBox Function MsgBox( prompt,buttons, title,helpfile,context) optional text displayed in the message box prompt p items must be combined with & MsgBox The answer is & Xval & tons button codes vbokonly 0 vbexclamation 48 vbokcancel 1 vbinformation 64 vbabortretryignore 2 vbdefaultbutton1 0 vbyesnocancel 3 vbdefaultbutton2 256 vbyesno 4 vbdefaultbutton3 512 vbretrycancel 5 vbdefaultbutton4 768 vbcritical 16 vbsystemmodal 4096 vbquestion 32 MsgBox result is button clicked by user 9 MsgBox Function MsgBox Return Value vbok 1 vbcancel 2 vbabort 3 vbretry 4 vbignore 5 vbyes 6 vbno 7 Putting line breaks into the message displayed d 10 5

UserForms (custom dialog boxes) the most flexible (and complicated) user interface feature Illustrate by example: a typical engineering formula Calculate the Reynolds Number for liquid flow in a pp pipe Du Re= : fluid density D: pipe inside diameter u: average fluid velocity : viscosity Typical units and values kg lb m : 900 55 m ft D: 55 mm 209in 2.09 3 u: m ft 2 5 : s s 3 0.005 Pa s 3cP 11 UserForms Insert a UserForm in the Visual Basic Editor (VBE) New and empty UserForm 12 6

UserForms change name and title Properties window lists properties of selected object, here the entire userform 13 UserForms Add title and field for density Add textbox for value change caption Properties window now refers to the label object 14 7

UserForms Add a frame to contain the units choices remove frame caption Add an option button in the frame for one units choice change title & caption stretch button so caption shows 15 UserForms change default button value to true add button for alternate units with caption and default false add similar entries for pipe diameter, velocity and viscosity 16 8

UserForms add a command button to compute the answer change command button name, caption & font 17 UserForms add a Quit button with similar formatting the UserForm is complete, but two important background elements are missing: 1) there is no way for the UserForm to appear for use 2) when the Compute and Quit buttons are clicked, nothing will happen there is no VBA code behind them We ll deal with 2) first. 18 9

UserForms double-click the Compute Re button here, we must add code to carry out the calculations necessary and display the Reynolds Number result convert units, as required compute the Reynolds Number and ddisplay the result 19 UserForms insert a new module and add this Sub to start the UserForm double-click the Quit button and add the code to remove ( unload ) the UserForm Run the StartReynoldsNumber macro and enter values with units selected 20 10

UserForms click the Compute Re button click OK then or 1) you can set up and compute other cases 2) you click the Quit button to close out the UserForm UserForms can be loaded automatically when the workbook is opened. This is called an event handler. And they can be unloaded automatically when the workbook is closed. Although this is a good example of the use of UserForms, there are many other options and possibilities. You may need a good VBA reference book to take advantage fully of the potential of UserForms. 21 11