# Working with Numbers

Almost every procedure you write in Microsoft® Visual Basic® for Applications (VBA) uses numeric values in some way. For optimal performance and efficiency, and for accuracy in calculations, it is important to understand the different numeric data types and when to use which.

#### In This Section

The Integer, Long, and Byte Data Types
Understand the three data types in Microsoft® Visual Basic® for Applications (VBA) that can represent integers — the Integer, Long, and Byte data types.
The Boolean Data Type
Use the Boolean data type to specify True or False.
The Floating-Point Data Types
Specify extremely small or large numbers using the Single and Double data types.
The Currency and Decimal Data Types
Use these scaled integer data types when you cannot afford rounding errors and you do not require as many decimal places as the floating-point data types provide.
Conversion, Rounding, and Truncation
Formatting Numeric Values
Format numbers using the following Microsoft® Visual Basic® for Applications (VBA) functions: FormatNumber, FormatCurrency, FormatPercent, and Format.
Using the Mod Operator
Determine whether two numbers divide evenly or how close they come to dividing evenly using the Mod operator, which divides two numbers and returns the remainder.
Performing Calculations on Numeric Arrays
Understand how to perform mathematical functions on a variable set of numbers.

#### Related Sections

Getting the Most Out of Visual Basic for Applications
Write code that is fast, efficient, easy to read and maintain, and, if possible, reusable with a solid working knowledge of Microsoft® Visual Basic® for Applications (VBA) — what features the language includes and what you can do with it.
Working with Strings
Understand how to get information from strings.
Working with Dates and Times
Manipulate date values in Microsoft® Visual Basic® for Applications (VBA), and understand how VBA stores date values internally.
Working with Files
Understand the Microsoft Scripting Runtime object library, and work with drives, folders, and files as objects.
Understanding Arrays
Use arrays when you must store a number of values of the same type, but you do not want to create individual variables to store them all.
Tips for Defining Procedures in VBA
Define a Function or Sub procedure, and use the options available to you to make your code more extensible or more flexible.
Optimizing VBA Code
Understand how to streamline your Microsoft® Visual Basic® for Applications (VBA) code to streamline your memory requirements.
Show: