Because VBA is a programming language, it shares common principles and elements with other languages. Ones of them are variables.
A variable is a reserved place in a computer memory that can be used by a program. Excel stores there the value assigned to that variable.
Declaring Variables
When you declare the variable, you can define what kind of data you want to store there. For example:
With data type
Dim myVal As Integer
It means that you reserve 2 bytes for the integer value.
Without data type
If you declare value without data type
Dim myVal
VBA will automatically create its default type called Variant. This data type can be very handy because it changes its type depending on what you actually do with the variable. For example, if you enter „56”, it can behave as a number or as a text string.
Declaring multiple variables at once
When you want to declare multiple variables, you can create each declaration in a new line.
Dim first As Integer Dim second As Double Dim third As Single
But there is another faster method where you need only one line of code.
Dim first As Integer, second As Double, third As Single
If all of your variables are of the same type, you still have to declare it to each variable separately.