Dim VBA – Declare Variable
The Dim Keyword in VBA
You can use the Dim keyword in order to declare a variable in VBA:
Dim n as Integer
Dim stands for Dimension. When you use the Dim keyword, state the name and data type of the new variable.
This is shown in the code below:
Sub DeclaringAVariableUsingDim() Dim productName as String Dim myNumber as Integer Dim myRange as Range Dim wb as Worksheet Dim myValue as Boolean End Sub
We have declared five different variables in the above code, and used five different data types. You can learn more about how to name variables and variable data types in our VBA Data Types – Variables and Constants tutorial where we go into detail about what variables are, how to name them and the different data types available in VBA.
VBA Coding Made EasyStop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!