Variant data type is the default data type used by VBA. Because a variant can contain any type of data, VBA treats all variables you do not assign a data type as variants. But because of the processing required by

VBA to determine the data type, variants work best when you use them for values that you cannot type with the standard VBA data types. The following table lists VBA variant data types:






+/-79,228,162,514,264,337,593,543,950,335 with no decimal point or +/-7.9228162514264337593543950335 with 28 places to the right of the decimal



-1.79769313486232E308 to -4.94065645841247E-324 (with numbers) for negative values, 4.94065645841247E-324 to 1.79769313486232E308 for positive values


22 + string length

0 to 2,000,000,000 (with characters)


Variables are essentially user-defined storage spaces. You can declare a variable to contain a specific type of data value.

This chapter describes the process of declaring a variable to use within a macro. Chapter 5 provides additional information about dealing with variables.

You can make variable names almost anything including any combination of alphabetic characters, numbers, and some punctuation characters — such as

#, $, %, ., and ! — as long as the first character is alphabetic. You cannot use spaces as part of the name.

VBA is not case sensitve. You can make the names upper- or lowercase characters, or any combination.

You should make variable names descriptive so you can easily determine what the variable contains. For example, Cell_Total indicates that the variable contains the total of adding cells. Keep in mind that the name cannot exceed 254 characters.

0 0

Post a comment