Struggling to know How to declare a variable in Excel VBA??
Declaration of Variables means assigning types to the variables. There are many methods available in declaring variables in VBA. We can see them one by one.
1) Casual declaration:
Here there is no data type or must needed declaration on any data type is required on the variables in VBA. Variable can be loaded as is.
For Example:
a = 10
b = "Test"
In the above example, type of "a" is auto declared as "Integer" type, "b" is auto declared as "String" type.
2) Fixing specific one:
In this method before assigning value to the variable the type of the variable will be declared.
For Example:
Dim a As Integer
Dim b As String
a = 10
b = "Test"
In the above example, variable type is declared already. In this scenario if we are assigning any other value to variables a or b we will be resulted in exception.
3) Option Explicit:
Once we added this method or declared "Option Explicit" in code then it is mandatory that each and every variable must declare with data type.
Thanks and Regards,
Gokul Tech Team
good to watch great effort
ReplyDelete