Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Integer
2.1.
Code
2.2.
Result
2.3.
Explanation
3.
String
3.1.
Code
3.2.
Result
3.3.
Explanation
4.
Double
4.1.
Code
4.2.
Result
4.3.
Explanation
5.
Boolean
5.1.
Code
5.2.
Result
5.3.
Explanation
6.
FAQs
7.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Variables

Author Prachi Singh
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

The instant at which Excel VBA knows that the user is using a variable is known as the declaration of a variable. Assigning a value to a variable is known as initialization.

The command button is used to execute the lines of code.

Read More About, C++ Basics

Integer

Integer variables act as the container for the whole numbers.

Code

Dim x As Integer
x = 9
Range("A1").Value = x

Result

Explanation

First-line declares the variable ’x’ as an integer.  The second line initializes the value of the variable ‘x’ as 9. Finally, we store the value of x to cell A1.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

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.

Previous article
Range Object
Next article
If Then Statement
Live masterclass