Data Types in VBA (with Range Table and Naming Prefixes)

VBA supports various data types, and choosing the right one has a direct impact on execution speed, memory usage, and preventing type conversion errors.
In this article, we’ll review all numeric and non-numeric data types in VBA along with their value ranges, memory sizes, and recommended variable prefixes.

🔢 Numeric Data Types in VBA

VBA provides several numeric data types that differ in precision, memory usage, and value range.
The following table summarizes this information:

Data Type Value Range Memory Usage Prefix
Byte0 to 2551 bytebyt
Integer-32,768 to 32,7672 bytesint
Long-2,147,483,648 to 2,147,483,6474 byteslng
LongLong1-9,223,372,036,854,775,808 to 9,223,372,036,854,775,8078 bytes
LongPtr2-2,147,483,648 to 2,147,483,647 (32-bit)
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (64-bit)
4 bytes – 32-bit
8 bytes – 64-bit
Single-3.402823E+38 to -1.401298E-45 (negative)
1.401298E-45 to 3.402823E+38 (positive)
4 bytessng
Double-1.79769313486232E+308 to -4.94065645841247E-324 (negative)
4.94065645841247E-324 to 1.79769313486232E+308 (positive)
8 bytesdbl
Currency-922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytescur
Decimal3+/-79,228,162,514,264,337,593,543,950,335 (no decimals)
+/-7.9228162514264337593543950335 (28 decimals)
14 bytes
Variant (with numbers)Includes all Double values16 bytesvnt
1. Available only in VBA 7.0 and Office 64-bit.
2. Not an actual data type; it maps to Long on 32-bit systems and LongLong on 64-bit systems. Useful for cross-platform compatibility.
  • 3 Declared as Variant and converted using the CDec function.
  • 💡 Tip:
    For financial calculations requiring high precision, use the Currency type. It prevents rounding errors common with floating-point arithmetic.

    📘 Example:

    Dim curSalary As Currency
    curSalary = 125000.75

    Non-Numeric Data Types in VBA

    Non-numeric data types are used to store text, dates, objects, and data structures.
    The following table lists their main characteristics:

    Data Type Value Range Memory Usage Prefix
    Boolean1True or False2 bytesbln
    CollectionUnknownUnknowncol
    DateJanuary 1, 100 to December 31, 99998 bytesdtm
    DictionaryUnknownUnknown
    ObjectAny object reference4 bytesobj
    String (variable-length)0 to approximately 2 billion characters10 bytes + string lengthstr
    String (fixed-length)21 to about 65,400 charactersString lengthstr
    Variant (with characters)0 to approximately 2 billion characters22 bytes + string length (24 bytes on 64-bit)vnt
    User-defined (using Type)3Depends on declared field typesDepends on declared field types
    1. When a numeric value is converted to Boolean, zero equals False and all other numbers equal True. When converted back, False becomes 0 and True becomes -1.
    2. To declare a fixed-length String, specify the length after an asterisk (*). Example: Dim s As String * 3
    3. Defined using the Type statement.

    💡 Tip:
    In VBA, String variables can be either variable-length or fixed-length.
    When working with large text files or memory-sensitive operations, using a fixed-length string can improve performance.

    📘 Example:

    Dim strCode As String * 3
    strCode = "ABC"

    ⚙️ Tips for Choosing the Right Data Type

    🔸 Speed vs. Memory:
    Types such as Integer and Long use less memory, but if you need decimal precision, use Single or Double.

    🔸 Limit the use of Variant:
    Although Variant is flexible and can hold any data type, it slows execution and increases memory usage.

    🔸 Consider Office version and system architecture:
    If your code will run on both 32-bit and 64-bit systems, use LongPtr to ensure compatibility without changing the data type manually.

    📚 Reference

    Data Type Summary – Microsoft Docs

    🧭 Summary

    Choosing the proper data type in VBA is one of the foundations of professional code design.
    When working on large projects or heavy Excel files, always consider the expected value range and select the type accordingly.
    In the next post, we’ll cover Type Conversion and functions such as CInt, CDbl, CStr, and more.