String
String variables act as the storage container for a group of characters.
Code
Dim vegetable As String
vegetable = "potato"
Range("A1").Value = vegetable
Result
Explanation
First line declares the variable vegetable as a string. The second line initializes the value of the vegetable as potato. Finally, we store the value of the vegetable in cell A1.
Double
Double acts as the storage for integers but can also store value after comma insertion.
Code
Dim x As Double
x = 7.8
MsgBox "value is " & x
Result
Explanation
The output will display the value as 7.8
Boolean
These variables either store the value as True or False.
Code
Dim continue As Boolean
continue = True
If continue = True Then MsgBox "Welcome to Coding Ninjas"
Result
Explanation
The Boolean variable is only intended to display the value as True.
FAQs
1. What are the different types of variables used in Excel VBA?
The different variables used are Integer, String, Double, and Boolean.
2. Which types of values are stored in the integer variable?
Whole Numbers.
3. Name the variable used for storing Text.
String
4. What is the return value of Boolean?
Boolean either returns the value as true or false.
5. What is the use of Double?
Double stores the value of integer type after comma insertion.
Key Takeaways
Congratulations on finishing the blog!! After reading this blog, you will grasp the concept of the Variables in Excel VBA.
If you are preparing yourself for the top tech companies, don't worry. Coding Ninjas has your back. Visit this link for a well-defined and structured material that will help you provide access to knowledge in every domain.