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.

Slides:



Advertisements
Similar presentations
ISOM3230 Business Applications Programming
Advertisements

PROGRAMMING IN VISUAL BASIC PART 1
Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
EXCEL VBA 101 Current Status Waiting Using Excel/VBA to Speed-up Daily Data Processing An Introduction to VBA Yongjun Chen Click Me to Start …
Essence of programming  Branching  Repetitions.
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
© 2002 ComputerPREP, Inc. All rights reserved. Excel 2000: Customizing Excel and Using Macros.
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Collin College Excel Exam Review. True In Excel worksheets, rows are designated using numbers while columns are designated using letters.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
VBA for MS Excel Hamze Msheik. Open the Visual Basic Editor in Excel 2007 Click on the Microsoft Office button in the top left of the Excel window and.
Programming in Visual Basic
Microsoft Excel 2003 Illustrated Complete A Worksheet Formatting.
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
Using the Visual Basic Editor Visual Basic for Applications 1.
Adding Automated Functionality to Office Applications.
FIRST COURSE Excel Lecture. XP 2 Introducing Excel Microsoft Office Excel 2007 (or Excel) is a computer program used to enter, analyze, and present quantitative.
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.
Christopher Guertin VAMC – West Palm Beach, FL 1.
With Microsoft Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2007 Comprehensive.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
11 10/10/2005 BAE Spreadsheet Macros (Visual Basic for Applications) Slides to accompany an in-class demo of spreadsheet technique: Macro Programming.
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.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 7 BACKNEXTEND 7-1 LINKS TO OBJECTIVES Record & run a macro Record & run a macro Save as a macro-
Enhancing User Interaction Through Programming
Creating Macros Using VBA. Assigning a Macro to a Button Display the Forms toolbar. Click the Button icon. Click and drag the mouse pointer to specify.
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Microsoft Office Illustrated Introductory, Premium Edition A Worksheet Formatting.
Microsoft Office XP Illustrated Introductory, Enhanced A Worksheet Formatting.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Visual Basic for Applications Macro Programming For Microsoft Office.
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.
Using Visual Basic for Applications in Microsoft Project Sean Vogel.
Chapter 9 Macros And Visual Basic For Applications.
Microsoft® Excel Key and format dates and times. 1 Use Date & Time functions. 2 Use date and time arithmetic. 3 Use the IF function. 4 Create.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
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.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
Excel Spreadsheets Formatting and Functions ICS100 – Spring 2007 D. Pai.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Excel Information. Basics In Excel there are rows, columns and cells. Row- The horizontal lines in the workbook –These are identified by numbers on the.
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
Chapter 6 Modifying Cell Styles
Microsoft Excel Illustrated
IE 8580 Module 4: DIY Monte Carlo Simulation
Exploring Excel Chapter 7 Automating Repetitive Tasks: Macros and
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
MS-EXCEL SUMMARY.
Data Validation and Protecting Workbook
Computer Fundamentals
Microsoft Access Illustrated
Microsoft Office Illustrated
Excel VBA Day 3 of 3 Tom Vorves.
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Unit 42 : Spreadsheet Modelling
Introducing VBA Macros
Formatting a Worksheet
Introduction to Spreadsheets
Exploring Microsoft Excel
Chapter 6 Modifying Cell Styles
Microsoft Excel 2007 – Level 2
Presentation transcript:

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 solve using Excel but you can see how VB works Parts How to start Syntax Commands, variables, loops

Parts of VBA Objects – Workbook, sheet, cell, range of cells, chart Properties – What to do with object Open, Select Methods – Action Clear, Print

Steps Objects & Properties and Objects & Methods are separated by a period To do anything, have to select (make active) first Add comments using REM or single apostrophe ‘ Can print the VB module using File/Print Sheets(“sheet1”).select objectproperty Sheets(“sheet1”).PrintOut objectmethod

How to start Developer tab and click the Visual Basic button in the Code group. Visual Basic Editor – Insert Module Visual Basic statements or commands are contained in SUB procedure and are named – Sub NameYouMakeUp() – first line – End Sub – last line Name should reflect what the module does – Sub AddCells()

Some Code Sub AddCells() sheets(“sheet1”).select [d2]=[b2]+[c2] End Sub Three ways to select cell location 1) Cell locations have brackets [c2] 2) By row and column Cells(2,3) =this is used for incrementing 3) With the range keyword Range(“c2”) also range(“b3:d3”).select

Testing and Executing In the Visual Basic Editor select run from toolbar In excel select View tab/Macros/View macros/select macro from list then run button You can create a button to run macro – Customize the Quick Access Toolbar and add the button object – Select the button object, create – Select the macro – Change the button text

Variables Hold information that can change – Results of a calculation – Or to make comparisons Rules – Must begin with a letter Can contain alpha characters and/or digits – There are some reserved words – Maximum length of name 255 characters

Variables (cont.) One variable on left of equal sign Cost = 50 Equal sign means “set” Sub Rev() Sheets(“sheet1”).Select Cost = 50 SellPrice = 90 Revenue = SellPrice – Cost End Sub – only one decimal point allowed, no commas or dollar signs Let Cost = 50 (Let is optional)

Text Variables and Parameter Query String data Title = “Hello World” [b7] = title Request data [b2] = InputBox(“title”,”what to enter”) [c2] = InputBox(“title”,”what to enter”) [d2] = [b2] + [c2] – If it is text then it will concatenate result not add

Counting and Incrementing The sum of something or how many times Add 1 to a variable – M = M + 1 To move to next column or row use cell reference – Cells(M,2) If you are running a total you will need another variable, initialize to zero

Decision Making To continue or what action to take If (logical expression) then (execute) True or False it will continue Decide between two actions If (logical expression) then () else ()

Looping Loop is terminated with IF FOR/NEXT DO/WHILE – condition is true DO/UNTIL - while condition is false

Other commands Sheets.Add after := sheets(“sheet4”) Sheets(“Sheet1”).Copy before := sheet2 Sheets(“sheet2”).select Activewindow.selectedsheets.Delete Range(Cells(5,3),Cells(9,3)).Value = 0 Range(Cells(13,4),Cells(22,4)).ClearContents

Cell Attributes Range(“b3”).font.bold=true Range(“b3”).font.name=“comic sans ms” Range(“b3”).font.italic=true OR With range(“B3”).font.size = 20.font.bold=true.font.name=“comic sans ms”.font.italic=true End With

More Cell Attributes Columns(“F”).select Selection.columnwidth=12 OR Columns(“B:H”).select Rows(“2”).select Two decimals Range(“b6:e15”).select Selection.NumberFormat=“0.00”

Summary Create and run VB procedures Parts How to start Syntax Commands, variables, decision making and loops