Excel & Visual Basic for Applications (VBA)

Similar documents
Excel & Visual Basic for Applications (VBA)

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

Programming in Access VBA

Microsoft Access Basics

Final Exam Review: VBA

Financial Data Access with SQL, Excel & VBA

National Database System (NDS-32) Macro Programming Standards For Microsoft Word Annex - 8

Excel 2010: Create your first spreadsheet

Microsoft' Excel & Access Integration

How To Create A Report In Excel

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

Microsoft Access 2010 Overview of Basics

Introduction to Microsoft Access 2003

Computer Skills: Levels of Proficiency

Like any function, the UDF can be as simple or as complex as you want. Let's start with an easy one...

To create a histogram, you must organize the data in two columns on the worksheet. These columns must contain the following data:

Utility Software II lab 1 Jacek Wiślicki, jacenty@kis.p.lodz.pl original material by Hubert Kołodziejski

Formulas & Functions in Microsoft Excel

Introduction. Why (GIS) Programming? Streamline routine/repetitive procedures Implement new algorithms Customize user applications

OpenOffice.org 3.2 BASIC Guide

What is Microsoft Excel?

Part A: Introduction to Excel VBA

Sample- for evaluation only. Advanced Excel. TeachUcomp, Inc. A Presentation of TeachUcomp Incorporated. Copyright TeachUcomp, Inc.

Overview of sharing and collaborating on Excel data

A Comparison of SAS versus Microsoft Excel and Access s Inbuilt VBA Functionality

The FTS Real Time System lets you create algorithmic trading strategies, as follows:

Part 1: An Introduction

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Excel Level Two. Introduction. Contents. Exploring Formulas. Entering Formulas

Task Force on Technology / EXCEL

WEBFOCUS QUICK DATA FOR EXCEL

Spreadsheet Modelling

INTRODUCTION TO EXCEL

VBA PROGRAMMING FOR EXCEL FREDRIC B. GLUCK

A Basic introduction to Microsoft Access

Excel 2007 Tutorials - Video File Attributes

Excel Programming Tutorial 1

CREATING FORMAL REPORT. using MICROSOFT WORD. and EXCEL

Formulas & Functions in Microsoft Excel

MS Access Lab 2. Topic: Tables

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

Pastel Evolution BIC. Getting Started Guide

Microsoft Office 2010: Access 2010, Excel 2010, Lync 2010 learning assets

What is a database? The parts of an Access database

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

3 What s New in Excel 2007

2. The Open dialog box appears and you select Text Files (*.prn,*.txt,*.csv) from the drop-down list in the lower right-hand corner.

Excel 2003 Tutorial I

Using Excel for Handling, Graphing, and Analyzing Scientific Data:

Training Needs Analysis

As in the example above, a Budget created on the computer typically has:

Microsoft Access 2007 Introduction

with VBA

EXCEL PIVOT TABLE David Geffen School of Medicine, UCLA Dean s Office Oct 2002

NEXT-ANALYTICS lets you specify more than one profile View in a single query.

LabVIEW Report Generation Toolkit for Microsoft Office

Excel 2007: Basics Learning Guide

Step 3: Go to Column C. Use the function AVERAGE to calculate the mean values of n = 5. Column C is the column of the means.

Intro to Excel spreadsheets

Database Automation using VBA

PLANNING (BUDGETING)

The FTS Interactive Trader lets you create program trading strategies, as follows:

WHAT S NEW IN MS EXCEL 2013

Getting Started Guide

Advanced Excel Charts : Tables : Pivots : Macros

Excel Working with Data Lists

Microsoft Access Glossary of Terms

Access Queries (Office 2003)

Automating PrecisionTree with VBA

Microsoft Office Word 2010: Level 1

Microsoft Excel 2010 Training. Use Excel tables to manage information

Getting Started with Excel Table of Contents

Excel & Visual Basic for Applications (VBA)

How To Use Excel With A Calculator

BID2WIN Workshop. Advanced Report Writing

Figure 1. An embedded chart on a worksheet.

Excel Reporting with 1010data

Microsoft Excel 2007 Level 2

Analyzing Data Using Excel

Using Excel (Microsoft Office 2007 Version) for Graphical Analysis of Data

Microsoft Excel Introduction to Microsoft Excel 2007

4. The Third Stage In Designing A Database Is When We Analyze Our Tables More Closely And Create A Between Tables

Adobe Acrobat 9 Pro Accessibility Guide: Creating Accessible PDF from Microsoft Word

Hummingbird Enterprise

HYPERION SMART VIEW FOR OFFICE RELEASE USER S GUIDE

Getting Started Guide SAGE ACCPAC INTELLIGENCE

MICROSOFT EXCEL 2010 ANALYZE DATA

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

PivotTable and PivotChart Reports, & Macros in Microsoft Excel

Tommy B. Harrington 104 Azalea Drive Greenville, NC

WinEst User-Defined Filters and Advanced Reports. Ken Regier Sr. Business Consultant Trimble Buildings

Excel Formatting: Best Practices in Financial Models

Microsoft Excel 2010 and Tools for Statistical Analysis

Microsoft Access 2003 Module 1

Unleashing Hidden Powers of Inventor with the API Part 1. Getting Started with Inventor VBA Hello Inventor!

Oregon State Bar Software Standards Software Proficiency Expectations (Items in bold are to be demonstrated)

Transcription:

Excel & Visual Basic for Applications (VBA) Object-oriented programming (OOP) Procedures: Subs and Functions, layout VBA: data types, variables, assignment 1 Traits of Engineers Florman s Engineering View 1 a commitment to science and to the values that science demands: independence, originality, dissent, freedom, tolerance a comfortable familiarity with the forces that prevail in the physical universe a belief in hard work in the quest for knowledge and understanding and in the pursuit of excellence a willingness to forego perfection in the interest of getting the product out the door a willingness to accept responsibility and the risk of failure a resolve to be dependable a commitment to social order with a strong affinity for democracy a seriousness of purpose, but not glumness a passion for creativity, compulsion to tinker and zest for change 1 from Florman, Samuel, The Civilized Engineer 2 1

Object-oriented Programming a computer-based entity that has properties and can be manipulated Excel has a pre-defined hierarchy of objects and properties It is also possible to define new objects, classes of objects, & properties in Excel, but we won t get to that in this course It starts with Excel itself the BIG object Excel is called the Application object There are other Application objects in the Microsoft Office and Windows environments [ Word, Access, etc ] Within the Excel Application object there is an extensive family tree of sub-objects, sub-sub-objects, etc. And any object, at any level, can have properties Properties are attributes of objects, while objects are entities 3 Excel s Object Hierarchy Application AddIn Name Workbook WorksheetFunction Chart CommandBar VBProject Worksheet and so on Excel s object structure is complex, so you need a roadmap to work with it. This is the Object Browser in the VBE. 4 2

The VBE Object Browser launch the Browser with this button on the VBE toolbar Application Property Object class You can also view the object family tree in VBA Help 5 6 3

7 Object Collections Workbooks Charts all currently-open workbook objects all charts contained in a particular workbook Sheets all sheets contained in a particular workbook Referring to objects in a collection Worksheets( Main ) Charts( XY ) Complete object references Application.Workbooks( Project6 ).Worksheets( Main ).Range( Pressure ) Can be simplified when unambiguous Workbooks( Project6 ).Worksheets( Main ).Range( Pressure ) Worksheets( Main ).Range( Pressure ) Range( Pressure ) 8 4

Properties, Methods and Events properties are attributes of objects methods are actions to be taken on objects events are happenings that objects respond to Examples: Range( A1 ).Width property Range( B2 ).Clear Open method event (workbook is opened) There are 1,000s of Objects, Properties, Methods, and Events, but there are only a few that you ll use all the time. And, when you need a new one, you can find it. So, don t be afraid of drowning in a sea of these things. 9 Object properties What do we do with them? examine their settings change their settings Examples 10 5

Object methods methods change properties or cause the object to do something Examples Note: the Copy method has a following argument, the destination for the copy 11 Using On-line help for VBA in some Excel installations, VBA Help will have to be installed from the Office 2000 CD/ROMs F1 shortcut key 12 6

Using the Answer Wizard Note that in VBA code, the function for square root is Sqr, not SQRT 13 Help Index 14 7

VBA program units: Subroutines and Functions Subroutine procedures are typically called subs or macros Subs: a VBA subprogram that can be executed by running it from Excel, from the VBE, or by being called by another VBA subprogram can be created with the macro recorder or typed in from scratch may have zero-to-several arguments that provide for values to be input to or output from the Sub Sub name (optional arguments) End Sub 15 Functions: a VBA subprogram that can be executed by using its name in a VBA expression or an Excel formula functions return values in place of their names functions cannot be recorded, but must be typed into the VBE functions may have zero-to-several input arguments Function name (optional arguments) End Function 16 8

Naming Rules for Subs and Functions Permissible characters: letters, numbers, some punctuation Must start with a letter Can t use #, $, %, &, or! Cannot look like a cell reference < 255 characters (!) Can t use spaces or periods VBA does not distinguish between upper and lowercase, but the first style entered will be remembered Use reasonably short names that carry a clear meaning Temperature may be better than Temp or T Mole_Fraction or MoleFraction both good 17 VBA Nuts and Bolts Data types, constants, variables, expressions, assignment Data types the most common: single, integer and string Single used for most numbers with decimal fractions and possibly exponents precision: about 6-to-7 significant figures range: from about 10 38 down to 10-39, both + and - uses 4 bytes of memory Integer used for most counting numbers range: from 32,768 to 32,767 uses 2 bytes of memory 18 9

String used to store text 1 byte is used for each character characters are stored according to the standard ASCII code Additional data types Double used for numbers with decimal fractions and possibly exponents where high precision or extended range are required precision: about 15-to-16 significant figures range: from about 10 308 down to 10-309, both + and - uses 8 bytes of memory Important: Excel uses double for the numbers stored in cells on the spreadsheet 19 Long Boolean (also called logical ) Object Variant used for integers where extended range is required range is about - 2 billion to + 2 billion each number uses 4 bytes of memory used for T/F information two constant values: TRUE and FALSE 2 bytes are used for each Boolean quantity used for any defined object takes up 4 bytes of memory adjusts automatically to the data type required chameleon data type storage requirements vary 20 10

There are additional data types for currency, date It is also possible to define new data types: user-defined Variables are identifiers for storage locations for one or more data types. It is useful to think of a variable as the name on the outside of a mailbox, where one or more values can be stored in the mailbox. When a data type is associated with a variable name, the mailbox can only store information of that type. When you write VBA code, it is possible to get away without declaring the data types of variables that you use. But, this is bad programming practice, so it is best to declare the types of all variables used in VBA. This requirement is enforced by putting the Option Explicit statement at the top of every VBA module you develop. 21 Enforcing variable declaration put Option Explicit statement at the top of every module or set VBE s Tools and VBE will do it for you! Options Require Variable Declaration 22 11