VBA Variables DataTypes Constants

VBA Variables, Data Types and Constants in Excel

VBA Variables, Data Types and Constants in Excel.Variables store values in a computer memory. Data types represents the what kind of data. Constants represents values.The variable values can change but constant values cannot change. All variables and constants consists of data type.

VBA Variables in Excel

We have to follow different instructions while naming a variable. Let us what are those instructions.

Rules to Name a Variable in VBA

We must follow the following rules while declaring a variable name.

  1. Variable Name must be less than 255 characters long
  2. VBA kywords or reserved words cannot use as a Variable Name
  3. It should not begin with number, always must begin with a letter
  4. Variables consists of only letters, numbers and underscore characters.
  5. It doesn’t allow space in the variable name.
  6. Variable name doesn’t allow period(.)
  7. We cannot use special characters like @,#,$.%,&,!, etc.


Dim sName
Where sName represents a variable name.

Read more about VBA Variables

VBA Data Types in Excel

We have many data types in MS Office Excel VBA. We have categorised data into two types. Those are numeric data type and non-numeric data types. Data types we use with Dim statement to declare variables. Declaring variables and its data types helps programmer and avoid mistakes. If data type is not specified, default it considers variant data type. It occupies more memory.

Dim sName as string
Where string represents the data type

Read more about VBA Data Types

VBA Constants in Excel

Constants in VBA helps to programmer to declare and assign value to use in module. Constant also like a variable but cannot change constant value. We use’Const’ keyword to declare constants. You can use either private or public while declaring constants.
We have two types of constants.
1. Built-in Constants
2. User defined constants.

Const MyVal As integer
Const MyVal=10
Where Const represnts the constant variable and it has value 10.

Read more about VBA Constants

Excel VBA Tutorial:

Please click on below link to go back to see Excel VBA Tutorial table of content.

Excel VBA Tutorial

Leave a Reply