Skip to main content

How to Declare Variable in Excel VBA

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

Comments

Post a Comment

Popular posts from this blog

Understanding the DATESINPERIOD Function in Power BI

                                              Power BI is a powerful business analytics tool by Microsoft that helps users visualize data and share insights across their organization. One of the key features of Power BI is its ability to handle time-based data with ease, thanks to its robust suite of time intelligence functions. Among these, the DATESINPERIOD function is particularly useful for analyzing data over specific time periods. In this blog post, we'll dive deep into the DATESINPERIOD function, exploring its syntax, usage, and practical applications.  What is the DATESINPERIOD Function?                         The DATESINPERIOD function is a DAX (Data Analysis Expressions) function used to return a table of dates shifted by a specified number of intervals (day...

Schema in SQL Database

 What is Schema?                              In a SQL database, Schema is the logical structure. It helps the user to categorize the data according to the nature of information available in that database. For Example: -                             In a factory we have multiple departments are available, details for each department staff collected and maintained in different forms. To categorize them under their working department it will be organized as per the department.                        Similarly, Schema helps user to categorize the data based on the information.  How to Create Schema:                               We can creat...

What is Database

  Definition:                A database is an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a  database management system (DBMS) .  What is Data?               Data is a raw or unprocessed information. Typically, the data is raw and there is no statistical or any analysis made before to understand whether it is a real one or not. Example:                    We are using smartphones with many social media applications. Each and every message as in the form of text, images (irrespective of formats), documents (irrespective of formats), links everything considered as Data.                      It can be processed by organizations, individuals or any other in need according t...