Introduction. Syntax Statements. Colon : Line Continuation _ Conditions. If Then Else End If 1. block form syntax 2. One-Line syntax. Do...

Similar documents
Construction Administrators Work Smart with Excel Programming and Functions. OTEC 2014 Session 78 Robert Henry

Excel & Visual Basic for Applications (VBA)

USC Marshall School of Business Marshall Information Services

Introduction to Microsoft Access 2003

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Microsoft Excel 2010 Part 3: Advanced Excel

Microsoft Access 2010 Overview of Basics

The Center for Teaching, Learning, & Technology

Microsoft Access 2010 Part 1: Introduction to Access

Appendix A How to create a data-sharing lab

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

3 What s New in Excel 2007

Excel Database Management Microsoft Excel 2003

INTERMEDIATE Excel 2013

Microsoft Excel 2010 Tutorial

Financial Data Access with SQL, Excel & VBA

Excel Reporting with 1010data

Microsoft' Excel & Access Integration

Creating Basic Excel Formulas

Differences in Use between Calc and Excel

Programming MS Excel in Visual Basic (VBA)

Overview of sharing and collaborating on Excel data

RIT Installation Instructions

Advanced Excel Charts : Tables : Pivots : Macros

Programming in Access VBA

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

Access 2010 Intermediate Skills

How To Insert Hyperlinks In Powerpoint Powerpoint

EXCEL VBA ( MACRO PROGRAMMING ) LEVEL SEPTEMBER AM-5.00PM MENARA PJ@AMCORP PETALING JAYA

Introduction To Microsoft Office PowerPoint Bob Booth July 2008 AP-PPT5

Intro to Excel spreadsheets

How to make a line graph using Excel 2007

Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

Introduction. Inserting Hyperlinks. PowerPoint 2010 Hyperlinks and Action Buttons. About Hyperlinks. Page 1

Computer Skills: Levels of Proficiency

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

Page 1 EXPERT. 1.1 Manage Multiple Workbooks Pages Where Covered Modifying existing templates. 356 (Step 7 Tip) Merging multiple workbooks

Scientific Graphing in Excel 2010

Microsoft Office. Mail Merge in Microsoft Word

Microsoft Office Access 2007 which I refer to as Access throughout this book

Chapter 9 Creating Reports in Excel

Microsoft Office Access 2007 Basics

Excel 2007 Basic knowledge

Content Author's Reference and Cookbook

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

Excel basics. Before you begin. What you'll learn. Requirements. Estimated time to complete:

ABSTRACT INTRODUCTION CLINICAL PROJECT TRACKER OF SAS TASKS. Paper PH

How To Create A Report In Excel

Working with Excel in Origin

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

Visual Basic Programming. An Introduction

Rows & Columns. Workbooks & Worksheets

Tommy B. Harrington 104 Azalea Drive Greenville, NC

In this example, Mrs. Smith is looking to create graphs that represent the ethnic diversity of the 24 students in her 4 th grade class.

Getting Started with Access 2007

Q&As: Microsoft Excel 2013: Chapter 2

Excel Using Pivot Tables

Data Tool Platform SQL Development Tools

Microsoft Access 2010

Exercise 1: Python Language Basics

Utilities ComCash

Excel 2007 Tutorials - Video File Attributes

Create a Poster Using Publisher

Basic Microsoft Excel 2007

JOOMLA 2.5 MANUAL WEBSITEDESIGN.CO.ZA

Getting Started with Excel Table of Contents

Introduction. Why Use ODBC? Setting Up an ODBC Data Source. Stat/Math - Getting Started Using ODBC with SAS and SPSS

Hands-on Exercise 1: VBA Coding Basics

Sage Intelligence Report Designer Add-In

Excel 2013 What s New. Introduction. Modified Backstage View. Viewing the Backstage. Process Summary Introduction. Modified Backstage View

Excel Reports User Guide

How To Use Excel With A Calculator

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

Highline Excel 2016 Class 26: Macro Recorder

Excel Using Pivot Tables

Lab 2: MS ACCESS Tables

Excel 2007: Basics Learning Guide

Microsoft Access 2010 handout

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

Excel 2010: Create your first spreadsheet

Microsoft Using an Existing Database Amarillo College Revision Date: July 30, 2008

Microsoft Office System Tip Sheet

Microsoft Excel 2007 and Tools for Statistical Analysis David R. Anderson, Dennis J. Sweeney, and Thomas A. Williams

PHP Tutorial From beginner to master

warpct.com Working with MS Excel 2003 Workbook courseware by WARP! Computer Training

To add a data form to excel - you need to have the insert form table active - to make it active and add it to excel do the following:

Task Force on Technology / EXCEL

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

OpenOffice.org 3.2 BASIC Guide

Using Microsoft Office XP Advanced Word Handout INFORMATION TECHNOLOGY SERVICES California State University, Los Angeles Version 1.

Developing Website Using Tools

SAS BI Dashboard 4.3. User's Guide. SAS Documentation

Introduction to Microsoft Access XP

Creating and Editing Workbooks. STUDENT LEARNING OUTCOMES (SLOs) After completing this chapter, you will be able to:

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Computer Training Centre University College Cork. Excel 2013 Level 1

Release 2.1 of SAS Add-In for Microsoft Office Bringing Microsoft PowerPoint into the Mix ABSTRACT INTRODUCTION Data Access

Transcription:

3 Syntax Introduction Syntax Statements Colon : Line Continuation _ Conditions If Then Else End If 1. block form syntax 2. One-Line syntax Select Case Case Case Else End Select Do...Loop For...Next While...Wend Objects Properties Methods Containers Getting Help Object Browser Reference Libraries VBA Library Other Reference Libraries Change or check references Objective: Become familiar with VBA syntax. Understand objects, properties, and methods.

3-2 Crystal's Introduction to Programming With Excel : Introduction Introduction When you are going to build a house, you would not use glass for walls, nor would you use bricks for windows. The type of material is a consideration when you construct. Chapter 2, Defining Variables, will be a great reference for you as you begin to build your code. The best way to learn VBA (on your own) is to start with Excel -- one reason is that there is a built-in macro recorder and you can examine the code that is created. The code that the macro recorder writes is often clunky, so knowledge of streamlining things helps out tremendously -- like, in Excel, use the array style of referencing to cells cells(4,2) is the cell in row 4, column 2; commonly known as B4. Using numbers to reference cells instead of the more familiar Letter-Number (i.e.: A1) style of referencing allows you to define variables and loop through cells more easily.

Chapter 3 Syntax: Syntax 3-3 Syntax This chapter is going to discuss syntax, the structure of the word order in a line of code. Code lines are composed of Statements. Statements A Statement can declare, define, calculate, test, assign, label, do. Statements must be syntactically complete and correct. A Statement generally occupies a single line. Colon : If you want to put more than one statement on a line, you can use a colon ( : ). Line Continuation _ If you want to break a statement onto two or more lines, you can use the line-continuation symbol, the underscore ( _ ) character. Conditions Life is full of choices. If one thing happens, it will cause another to happen. Simply put: If this, then that. A condition is a numeric or string expression that evaluates to TRUE or FALSE. When programming, a primary statement you can use to test a condition and decide what will happen is the IF statement.

3-4 Crystal's Introduction to Programming With Excel : If Then Else End If If Then Else End If The IF statement conditionally executes a group of statements depending on the value of a condition There are two forms of the IF statement syntax. 1. block form syntax If condition Then [ElseIf condition-n Then [Else [elseifstatements] [elsestatements]] End If When presenting syntax, anything that is optional is enclosed in square brackets. Therefore, the only required lines for this statement are: If condition Then End If Of course, it would be silly to test a condition if the outcome did not affect any course of action. If you don't have much to do if the condition is met, you can use a shortened form of the IF statement 2. One-Line syntax If condition Then [Else elsestatements]

Chapter 3 Syntax: Select Case Case Case Else End Select 3-5 Select Case Case Case Else End Select The Select Case Statement executes one of several groups of statements, depending on the value of an expression. Select Case testexpression [Case expressionlist-n [statements-n]]... [Case Else [elsestatements]] End Select

3-6 Crystal's Introduction to Programming With Excel : Do...Loop Do...Loop A Do statement repeats a block of statements while a condition is True or until a condition becomes True. Do [{While Until} condition] [Exit Do] Loop Alternatively, you can use this syntax:. Do [Exit Do] Loop [{While Until} condition]

Chapter 3 Syntax: For...Next 3-7 For...Next A For statement repeats a group of statements a specified number of times. For counter = start To end [Step step] [Exit For] Next [counter]

3-8 Crystal's Introduction to Programming With Excel : While...Wend While...Wend A While statement executes a series of statements as long as a given condition is True. While condition Wend

Chapter 3 Syntax: Objects 3-9 Objects Objects have Properties and Methods. In VBA, you manipulate objects -- their properties -- and launch their methods. Therefore, becoming familiar with objects will make you a better programmer. In Excel, you have workbooks and sheets, cells, ranges, graphs, etc -- as your objects In Access, you have tables and fields, queries, forms, reports, controls, etc -- as your objects Properties Properties are descriptive terms for an object. For example, a human object has properties like: hair color eye color height weight A cell (range) in Excel has properties such as: row column background color foreground color format value

3-10 Crystal's Introduction to Programming With Excel : Objects Methods Methods are things that an object can do. For example, with a human object, methods would be: eat sleep run jump A cell (range) in Excel has methods such as: activate add comment check spelling clear contents copy Containers Objects are contained in containers -- like a container with recordsets (in Access) or worksheets (in Excel). Among others, containers have a property called Count, which is how many objects it contains. Individual properties of an item in a container or the container itself can be determined (and often set), and methods can be launched. Getting Help... you can press Shift F1 to turn your mouse into a questioning pointer -- then click on a tool or menu option to get context-sensitive help

Chapter 3 Syntax: Objects 3-11... you can press F1 in a property to get help for that property (like on the property sheet in the design view of a form or Excel/Access or report in Access)... you can press F1 on a keyword in a module sheet to get help for that word Object Browser Press F2 in a module window the View the Object Browser... a GREAT place to get better knowledge of objects ;) The Object Browser is used to lookup objects, properties, and methods for objects in loaded reference libraries.

3-12 Crystal's Introduction to Programming With Excel : Reference Libraries Reference Libraries Reference Libraries contain information about objects. For instance, if you want to use Automation (formerly OLE Automation), you can set a reference to an application's type library. There are standard reference libraries that are always loaded. VBA Library The VBA Library contains fundamental functions (methods) and properties. From the Object Browser window, click on the Project/Library drop-down and choose VBA, instead of, for instance, <all libraries>. Look at the classes (categories) of functions/properties -- click on a class and then click on an item in the right (members) pane. To get the help for the item that you have selected, press F1. Note on Library References: Order as well as presence is important. Other Reference Libraries If you want information about objects specific to Excel -- or Sheets, Workbooks, Ranges -- change the library to Excel. If you want information about objects specific to Access -- like forms, reports, controls, etc -- change the library to Access.

Chapter 3 Syntax: Reference Libraries 3-13 Change or check references To check or change reference, from the menu bar, choose Tools, References... from a module window Explore the different libraries you have to loaded and see what is available in each. Check off a reference library that looks interesting to you and explore what is in it. Don't forget to uncheck unnecessary optional libraries when you are done browsing them, as loading libraries consumes resources.