Data Types

A Data Type refers to how VBA stores data in memory. VBA provides an assortment of built-in data types that you can use to handle your macro data, along with user-defined data types that you create.

In VBA, you do not specify the type of data you store in a variable when you declare it. You can enable VBA to automatically determine the data type, but this can slow down your code for large macros.

The size of a data type refers to the number of bytes it takes to store it. A byte is a group of bits, with a bit being the smallest storage unit and having a binary value or either 1 or 0. Realizing the number of bytes you require to store a data type can help you use memory more efficiently. Keep storage issues in mind when you create complex macros.

The following table lists the various data types for VBA integers.

DATATYPE

BYTES

RANGE OF VALUES

Byte

1

0 to 255

Integer

2

-32,768 to 32,767

Long

4

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

0 0

Post a comment