VBA for Excel. What is a spreadsheet? u An Excel spreadsheet is a set of worksheets  Each worksheets is made up of rows and columns of cells  Rows are.

Slides:



Advertisements
Similar presentations
An Introduction to Spreadsheets Using Number Magic Malcolm Wilson ICT Curriculum Support Teacher (Primary) Falkirk Council.
Advertisements

MS EXCEL is a spreadsheet application Excel covers: Calculation Graphic tools Pivot tables Macro programming language called VBA EXCEL is a part of MS.
Spreadsheet Software lesson 14. This lesson includes the following sections: Spreadsheet Programs and Their Uses The Spreadsheet's Interface Entering.
Intermediate Formulas & Functions Instructor: Rachel Baltus.
® Microsoft Office 2010 Excel Tutorial 1: Getting Started with Excel.
Microsoft Office XP Microsoft Excel
Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
Developing an Excel Application
Tutorial 8: Developing an Excel Application
XP New Perspectives on Microsoft Excel 2003, Second Edition- Tutorial 8 1 Microsoft Office Excel 2003 Tutorial 8 – Developing an Excel Application.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Excel and VBA Creating an Excel Application
Macros Excel built-in functions are great but limited Macros are a means for the user to define new functions A macro is a single command that automates.
Chapter 1 Introduction to Spreadsheet. Agenda Download the practice files Spreadsheet application Workbook and worksheet Toolbar Cell Formatting Printing.
Lecture Excel: Multiple Worksheets. Workbook and Worksheets Multiple worksheets in a single workbook. When saved, only a single workbook (XLS) is saved.
Adding Automated Functionality to Office Applications.
Chapter 12: Recording Macros Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
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.
Introduction to VBA. This is not Introduction to Excel We’re going to assume you have a basic level of familiarity with Excel If you don’t, or you need.
Lecture Roger Sutton CO357 Computing for Business and Accounting 13: Automation and Control (Macros and Form controls ) 1.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #3: Manipulating Excel Objects IE 212: Computational Methods for Industrial Engineering.
Excel Tutorial Enfield High School 2007.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-3 1 Lecture Outline Variable Scope Calling another subprogram Programming.
Project 9 Using Visual Basic for Applications (VBA) to Customize and Automate Excel Jason C. H. Chen, Ph.D. Professor of Management Information Systems.
XP Spreadsheet Presentation. XP Objectives Understand the use of spreadsheets and Excel Learn the parts of the Excel window Scroll through a worksheet.
# 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.
 Starting Excel 2003  Using Help  Workbook Management  Cursor Management  Manipulating Data  Using Formulae and Functions  Formatting Spreadsheet.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
CHAPTER 13 Creating a Workbook Part 2. Learning Objectives Work with cells and ranges Work with formulas and functions Preview and print a workbook 2.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Microsoft® Excel Use Insert Function. 1 Key and point to enter functions. 2 Navigate with and create named ranges. 3 Use range names in functions.
Excel Terms Worksheet: a grid of rows and columns Columns – labeled A, B, C, then AA, BB, etc. – 256 columns Rows – numbered 1, 2, 3 through 65,536 Cell.
Lecture Excel: Macros & Pivot Tables. Macros A macro is a series of commands that are stored and can be run whenever you need to perform the task.
Info copied from Microsoft Help Files Excel: Introduction Microsoft Office 2003.
Learning Objectives What is a spreadsheet and what is the difference between a spreadsheet and a worksheet? Start Excel, open an existing spreadsheet,
This is the first sheet of a spreadsheet workbook. The workbook begins initially with 3 work sheets. A spreadsheet is made of columns and rows. The intersection.
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.
4 - 1 Chapter 4: Advanced Excel Skills Management Science: The Art of Modeling with Spreadsheets, 3e S.G. Powell K.R. Baker © John Wiley and Sons, Inc.
The introduction of Microsoft Excel. Spreadsheet Basic.
CA I Excel Lesson 1. √Cells√Components√Other Terms active cell formula bar column cell name box label cell address Go To command row find range Excel.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
Chapter 9 Macros And Visual Basic For Applications.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
1. 2 Word Processing Word Processing is writing words and sentences on the computer. It is easy to change or move text in a word document. People use.
Spreadsheet Vocabulary.  Spreadsheet = an electronic document in which data is arranged in the rows and columns of a grid and can be manipulated and.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Microsoft Excel 2000 Analyzing Data Using Excel. ©2001 Paradigm Publishing Inc.Excel Section Title Bar Menu Bar Formatting Toolbar Standard Toolbar.
PERFORMING CALCULATIONS Microsoft Excel. Excel Formulas A formula is a set of mathematical instructions that can be used in Excel to perform calculations.
Spreadsheets What is Excel?. Objectives 1. Identify the parts of the Excel Screen 2. Identify the functions of a spreadsheet 3. Identify how spreadsheets.
Excel Spreadsheets Formatting and Functions ICS100 – Spring 2007 D. Pai.
Microsoft Excel ( XP-2003). Return to Table of Contents Table of Contents 1_ Introduction to ExcelIntroduction to Excel 2_ Overview of the Excel.
An electronic document that stores various types of data.
1 CA202 Spreadsheet Application Automating Repetitive Tasks with Macros Lecture # 12 Dammam Community College.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
COMPUTER LITERACY NOTES MS-EXCEL. SPREADSHEETS A spreadsheet is a computer equivalent of a paper ledger sheet. Excel allows you to create spreadsheets.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
The Advantage Series ©2005 The McGraw-Hill Companies, Inc. All rights reserved Chapter 12 Introducing Visual Basic for Applications Microsoft Office Excel.
Excel Tutorial 8 Developing an Excel Application
Excel: Macros & Pivot Tables
Microsoft Excel A Spreadsheet Program.
Microsoft Office Illustrated
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Lesson 16 Using What-If Analysis
Lesson 1 - Automating Tasks
Microsoft Office Excel 2003
Lesson 13 Working with Tables
Presentation transcript:

VBA for Excel

What is a spreadsheet? u An Excel spreadsheet is a set of worksheets  Each worksheets is made up of rows and columns of cells  Rows are numeric: 1, 2, 3, …  Columns are alphabetic: A, B, C, …  A cell contains data, or a formula

B6:E13 Row numbers column letters G2 : G8 Single Column Range A3 : E3 Single Row Range Read as “B6 to E13” A1 Single cell Cell Ranges

Numerical Data u Numerical data is any number (formatted or not) u Numerical data can be used in a formula u You can use Format/Conditional formatting with to alter the appearance of numeric data u Examples: %

Formatting Numbers

Formatting Dates

Formulas u A formula represents a mathematical calculation u Always starts with = u A formula contains:  Numbers  25.32, -56, 78  Cell addresses and ranges  A3, G24, A2:A54  Mathematical operators  Excel built-in functions  Today, Month, Sum =100*B5-D3+sum(R2:R15)

Today and Month functions u =TODAY() u =MONTH( a date)

Macros in Excel u A macro is a sequence of steps designed to accomplish a particular task  Just like a sub procedure in VB u In Excel, a user may create a macro in 2 ways  Record a sequence of steps in Excel using the macro recorder  Write a VB sub procedure using the macro editor

Macro Statements u A Macro always begins a Sub statement u A Macro ends with an End Sub statement

A Macro u To perform multiple actions on the same object Macros use  With  End With

The Selection object u Just as a user can select multiple cells simultaneously, a macro can select a region of a worksheet and apply changes to all the cells in that region

Recording a Macro

Putting a button onto a spreadsheet— in CS132 we use Control Objects u We can create a button and assign it to a Macro u This button is called a button control u View/Toolbars/Visual Basic u Then choose the button control

Adding the button control

Command Button Label Text box Option Button Check Box Image View/Toolbars/ Visual Basic List boxes The Visual Basic Toolbar

u Click on the tools icon to display the controls toolbox u After you add a control, right click on it to display the properties box Using the Control Toolbox & Property Box

Sample Command Button name = cmdStart caption = text that appears on the button (Start) enabled = true or false You must follow good programming practice u Object names must be meaningful * cmdExit * cmdStart An object and its properties

This is done by putting the desired letter in the Accelerator property in the properties box (note lower case only matters if more than one letter is present) s ( not S) Accelerator Property

Referring to a Worksheet in VBA u An index number is a sequential number assigned to a sheet, based on the position of its sheet tab u The following procedure uses the Worksheets property to activate worksheet one in the active workbook. Sub FirstOne() Worksheets(1).Activate End Sub

Properties Range("A1").Value = 99 The Value property is what the cell holds, in this case 99 Range("B2:B7").Interior.Color = vbYellow This changes the color of the cells in "B2:B7" to yellow. Methods We can use Range(“A1”).Select This makes “A1” the active cell Cell Ranges in VBA

A1-style references using the Range property ReferenceMeaning Range("A1") Cell A1 Range("A1:B5") Cells A1 through B5 Range("C5:D9,G9:H16") A multiple-area selection Range("A:A") Column A Range("1:1") Row 1 Range("A:C") Columns A through C Range("1:5") Rows 1 through 5 Range("1:1,3:3,8:8") Rows 1, 3, and 8 Range("A:A,C:C,F:F") Columns A, C, and F

u Cells(2,2).Value refers to R2C2 below Remember, row first, then column B3 is the same as Cells(3,2) Cells Notation

Range("B1").Value = 8 Range("B2").Value = 8 Can also be written: Cells(1,2).Value = 8 Cells(2,2).Value = 8 Cells vs. Range

Deleting data u You can clear the contents of a range using the ClearContents method: Private Sub cmdClear_Click() Range("D:D").ClearContents End Sub u Note: ClearContents does not clear the formatting, just the numbers or formulas contained within the cells.

Event handling for VBA objects The various objects present in an excel application (application, worksheet, etc.) generate events that can be handled Working with such events is beyond the scope of this class

Documentation /documentation/default.aspx