VBA for Excel 2007 tutorial-VBA Variable and Data type
VBA Variable and Data type
When writing code with any programming language, you will need something that can store the data temporarily for using in calculations or information presentation. It is called variable. The data can be store in different types (e.g. Number, String, Date, Boolean, etc). -Variable: a variable is referred to the location of memory to store a value. -Data type: The most common VBA data types are: Byte: Stores positive values ranging from 0 to 255.
his type will use 1 byte of memory size. Integer: Stores both negative and positive non-decimal values ranging from -32,768 to 32,767. This type will use 2 bytes of memory size. Long: Stores both negative and positive non-decimal values ranging from -2,147,483,648 to 2,147,483,647. It uses 4 bytes of memory size. Single: Stores both negative and positive decimal values ranging from -3.402823E38 to -1.401298E-45 for negative values and 1.401298E-45 to 3.402823E38 for positive values. The long type uses 4 bytes of memory size. Double: Stores both negative and positive decimal values ranging from -1.79769313486231E308 to -4.94065645841247E-324 for negative values and 4.94065645841247E-324 to 1.79769313486232E308 for positive values. It uses 8 bytes of memory size. Date: Stores date/time values. It uses 8 bytes of memory size. Boolean: Stores logical values—true or false. This type consumes 2 bytes of memory size. Currency: Stores currency values ranging from -922,337,203,685,477.5808 to 922,337,203,685,477.5807. It uses 8 bytes of memory size.
Variant: Stores any values. It uses 16 bytes or more than this of memory size.
String: Stores text values. Its use of memory depends on the length of text to store.