Preview

Vba Introduction

Better Essays
Open Document
Open Document
10854 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Vba Introduction
An Introduction to VBA in Excel
Robert L. McDonald† First draft: November, 1995 November 3, 2000



Abstract This is a tutorial showing how to use the macro facility in Microsoft Office—Visual Basic for Applications—to simplify analytical tasks in Excel.

Contents
1 Introduction 2 Calculations without VBA 3 How to Learn VBA 4 Calculations with VBA 4.1 Creating a simple function . . . . . . . . . . . . 4.2 A Simple Example of a Subroutine . . . . . . . 4.3 Creating a Button to Invoke a Subroutine . . . 4.4 Functions can call functions . . . . . . . . . . . 4.5 Illegal Function Names . . . . . . . . . . . . . . 4.6 Differences Between Functions and Subroutines 3 3 4 5 5 7 7 8 9 9

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

∗ Copyright c 1995-2000 Robert L. McDonald. Thanks to Jim Dana for asking stimulating questions about VBA. † Finance Dept, Kellogg School, Northwestern University, 2001 Sheridan Rd., Evanston, IL 60208, tel: 847-491-8344, fax: 847-491-5719, E-mail: r-mcdonald@northwestern.edu.

CONTENTS

2

5 Storing and Retrieving Variables in a Worksheet 5.1 Using a named range to read and write numbers from spreadsheet . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Reading and Writing to Cells Which are not Named. . . 5.3 Using the “Cells” Function to Read and Write to Cells.

10 the . . . . . . . . . 11 12 13

6 Using Excel Functions 13 6.1 Using VBA to compute the Black-Scholes formula . . . . . . 13 6.2 The Object Browser . . . . . . . . . . . . . . . . . . . . . . . 15 7 Checking for Conditions 16

8 Arrays 17 8.1 Defining Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 18 9 Iterating 19 9.1 A simple for loop . . . . . . . . . . . . . . . . . . . . . . . . . 20 9.2 Creating a binomial tree . . . . . . . . . . . . . . . . . . . . . 20 9.3 Other kinds of loops . . . . . . . . . . . . . . . . . . . . . . . 22 10 Reading and Writing Arrays 10.1

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Attach supporting Microsoft® Excel® tables and graphs to your paper. Spreadsheets must detail all calculations.…

    • 467 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    The aim of this guide is to teach you the basics of using a range of formulas in Microsoft Office Excel; this guide covers the following formulas: Addition; Subtraction, Multiplication, Division, Average & Percentage.…

    • 2823 Words
    • 12 Pages
    Good Essays
  • Good Essays

    In this project, you will create a named range and use it to set data validation. You will use a PMT function to calculate a value and then use it in a two-variable data table. You will also enter VLOOKUP functions to return values from a table, and format cells in the workbook. You will also audit a worksheet and correct errors.…

    • 566 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    404 Lesson 2

    • 336 Words
    • 4 Pages

    Directions: Each question of this assignment should be prepared as a separate sheet in one Excel file. Please change the sheet names at the bottom of the page to the question number. Then, follow the directions for each question below. Be sure to show your calculations and label your work for full credit. This assignment is worth 50 points. The grading rubric may be previewed in the Cost Behavior Drop Box.…

    • 336 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Assignment 2

    • 1856 Words
    • 7 Pages

    a. 3 points: Use built-in Excel functions to find the minimum and maximum values of x. That is,…

    • 1856 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    Unit 42 M3

    • 430 Words
    • 2 Pages

    The following states some of the automated features available within Excel spreadsheets. By implementing these within the spreadsheets can really benefit the end users.…

    • 430 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Exam 3

    • 772 Words
    • 4 Pages

    _____ help speed and simplify work because Excel users often work with the same types of problems repeatedly.…

    • 772 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    Ss2 Assesment

    • 1737 Words
    • 7 Pages

    1.1 Identify what numerical and other information is needed in the spreadsheet and how it should be structured…

    • 1737 Words
    • 7 Pages
    Powerful Essays
  • Powerful Essays

    • Maintain standard formatting of numbers throughout your model • Maintain standard formatting of worksheets throughout your model • Maintain standard column and row headings across multiple sheets…

    • 2666 Words
    • 11 Pages
    Powerful Essays
  • Powerful Essays

    Ross, Stephen. Westerfield, Randolph. And Jordan, Bradford. Essentials of Corporate Finance. Eighth Edition Irwin, 1996…

    • 1163 Words
    • 5 Pages
    Powerful Essays
  • Powerful Essays

    Business statistics

    • 2098 Words
    • 8 Pages

    Your assignment must be presented in Microsoft (MS) Word. Copy and paste any relevant Excel outputs to this document immediately before any relevant written answers to each task.…

    • 2098 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    Excel

    • 298 Words
    • 2 Pages

    For formulas just think back to the basic operations of math (parenthesis, adding, subtracting, dividing, etc.) – Excel does what you tell it to.…

    • 298 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Microsoft Excel

    • 1757 Words
    • 8 Pages

    In Microsoft Excel 2007, macros can be created using Microsoft Visual Basic. The following will show you how to create a macro using Microsoft Visual Basic:…

    • 1757 Words
    • 8 Pages
    Powerful Essays
  • Good Essays

    Protac

    • 827 Words
    • 4 Pages

    1. 2. 3. 4. 5. Solver y programación lineal El modelo Optimización Informes en excel Ejercicios…

    • 827 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Employment and Question

    • 289 Words
    • 2 Pages

    2. Construct an appropriate excel sheet (With all related Columns Specified) for First 2 Questions.…

    • 289 Words
    • 2 Pages
    Satisfactory Essays

Related Topics