Vba declaring assigning variable datatype in Excel
Variables are named memory locations in computer that stores a value of a specific data type
Variables can be of any data type such as Text,Number,Decimal,Charater or Object.
Variables should be "Declared" and "Assigned" to use it in the script.
Variables are declared using DIM keyword and assigned values using =
Declaring Variables using DIM keyword
- Sub HelloWorld()
- Dim variable As Integer
- Dim str As String
- Dim dbl As Double
- Dim obj As Object
- Dim flag as Boolean
- End Sub
Here is how it looks in the editor
Assigning Values to the variables
Here, the variable str holds a value of "Hello VBA", dbl holds "98.87" and variable holds "10"
These values can be accessed anywhere within the script and can be modified anytime