What Are Data Types

When you create Visual Basic procedures you have a purpose in mind: You want to manipulate data. Because your procedures will handle different kinds of information, you should understand how Visual Basic stores data. The data type determines how the data is stored in the computer's memory. For example, data can be stored as a number, text, date, object, etc. If you forget to tell Visual Basic the type of your data, it is assigned the Variant data type. The Variant type has the ability to figure out on its own what kind of data is being manipulated and then take on that type. The Visual Basic data types are shown in Table 3-1. In addition to the built-in data types, you can define your own data types, known as user-defined data types. Because data types take up different amounts of space in the computer's memory, some of them are more expensive than others. Therefore, to conserve memory and make your procedure run faster, you should select the data type that uses the fewest bytes but at the same time is capable of handling the data that your procedure has to manipulate.

Table 3-1: VBA data types

Data Type

Storage Size



1 byte

0 to 255


2 bytes

True or False


2 bytes

(long integer)

4 bytes

-2,147,483,648 to 2,147,483,647


(single-precision floating-point)

4 bytes

-3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values


(double-precision floating-point)

8 bytes

-1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values

Currency (scaled integer)

8 bytes

-922,337,203,685,477.5808 to 922,337,203,685,477.5807

Part I

Data Type

Storage Size



14 bytes

+7-79,228,162,514,264,337,593,543,950,335 with no decimal point; +7-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is



8 bytes

January 1,100, to December 31, 9999


4 bytes

Any Object reference



10 bytes + string length

0 to approximately 2 billion



Length of string

1 to approximately 65,400


(with numbers)

16 bytes

Any numeric value up to the range of a Double


(with characters)

22 bytes + string length

Same range as for variable-length String

User-defined (using Type)

Number required by elements

The range of each element is the same as the range of its data type.

0 0

Post a comment