Absolute Beginners Guide to VBA

     

Chapter 3. Understanding Program Variables

In this chapter

  • Learning why variables are useful

  • Declaring variables for use in your macros

  • Understanding the different types of variables

  • Learning to use array variables and constants

  • Using techniques that help you avoid the most common variable errors

Your VBA procedures often will need to store temporary values for use in statements and calculations that come later in the code. For example, you might want to store values for total sales and total expenses to use later in a gross margin calculation. Although you probably could get away with using the underlying application to store these values (in, say, a cell in an Excel worksheet), this almost always isn't very practical. Instead, VBA (like all programming languages) lets you store temporary values in variables. This chapter explains this important topic and shows you how to use variables in your VBA procedures.

Категории