(Last Updated On: 2021-12-28)

Variable Scope

ScopeTo Declare a Variable with This Scope
Single procedureInclude a Dim or Static statement within the procedure.
Single moduleInclude a Dim or Private statement before the first procedure in a module.
All modulesInclude a Public statement before the first procedure in a module.

VBA Built-In Data Types

Data TypeBytes UsedRange of Values
Byte1 byte0 to 255
Boolean2 bytesTrue or False
Integer2 bytes–32,768 to 32,767
Long4 bytes–2,147,483,648 to 2,147,483,647
Single4 bytes–3.402823E38 to –1.401298E-45 (for negative values);
1.401298E-45 to 3.402823E38 (for positive values)
Double8 bytes–1.79769313486232E308 to –4.94065645841247E-324 (negative values); 4.94065645841247E-324 to 1.79769313486232E308 (for positive values)
Currency8 bytes–922,337,203,685,477.5808 to 922,337,203,685,477.5807
Decimal12 bytes+/–79,228,162,514,264,337,593,543, 950,335 with no decimal point;
+/–7.9228162514264337593543950335 with 28 places to the right of the decimal
Date8 bytesJanuary 1, 0100 to December 31, 9999
Object4 bytesAny object reference
String (variable length)10 bytes + string length0 to approximately 2 billion characters
String (fixed length)Length of string1 to approximately 65,400 characters
Variant (with numbers)16 bytesAny numeric value up to the range of a double data type. It can also hold special values, such as Empty, Error, Nothing, and Null.
Variant (with characters)22 bytes + string length0 to approximately 2 billion
User definedVariesVaries by element