

{"id":96516,"date":"2021-06-23T09:00:52","date_gmt":"2021-06-23T03:30:52","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=96516"},"modified":"2021-06-07T13:26:42","modified_gmt":"2021-06-07T07:56:42","slug":"vba-variables-data-types-constants","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/","title":{"rendered":"VBA Data Types, Variables and Constants"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">This \u201cVBA Variables, Data Types &amp; Constants\u201d\u00a0 topic covers the concept of what variables and constants are. Knowing the difference between them and where to use them is really important.\u00a0<\/span><\/p>\n<h3>What is a Variable?<\/h3>\n<p><span style=\"font-weight: 400;\">A variable is a value that is declared in the code and used to store the value in the computer&#8217;s memory. It is very essential to declare your variable names and the data types. The data type defines which type of data will be stored in the variable.\u00a0<\/span><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Module ( )\u00a0\u00a0\r\nDim\u00a0 Variable_Name As Variable_DataType\u00a0\r\nEnd Sub<\/pre>\n<p><span style=\"font-weight: 400;\">In VBA, you can either declare a variable Implicitly or Explicitly.<\/span><\/p>\n<p><b>1. Implicitly<\/b><span style=\"font-weight: 400;\">:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"> If the user is not sure about the data type and if they are likely to change, then they can declare the data type as a variant. The variant data type can store all kinds of data except the fixed-length string data type. Below is an example of a variable declared Implicitly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Example<\/strong>: Dim myArticle as Variant<\/span><\/p>\n<p><b>2. Explicitly<\/b><span style=\"font-weight: 400;\">: When you use the &#8220;Dim&#8221; keyword in syntax, it&#8217;s declared explicitly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Example<\/strong>: Dim age As Integer<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To ensure Excel adds the variables to the option explicitly in the VBE, follow the below steps:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1: Go to the tools menu and click on the options.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96820\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options.png\" alt=\"VBA tools options\" width=\"871\" height=\"464\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options.png 871w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options-300x160.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options-768x409.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options-720x384.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options-520x277.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/tools-options-320x170.png 320w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">2: Under the editor label, make sure that there is a tick mark available beside the required variable declaration.\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96821\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor.png\" alt=\"Variables in VBA\" width=\"649\" height=\"570\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor.png 649w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor-300x263.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor-150x132.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor-520x457.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-var-dec-in-editor-320x281.png 320w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/a><\/p>\n<h3>How do VBA variables get started?<\/h3>\n<p><span style=\"font-weight: 400;\">Before executing the variables, we have to record a macro in the spreadsheet. To record a macro, follow the steps:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1: Go to the view tab and choose a macro.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2: Provide a name to the macro and click on a new button.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3: Record the Macro.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4: Stop the Macro, once it\u2019s done.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5: Now, click on the edit button in the dialog box to open the vba code editor.<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96839\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1.png\" alt=\"VBA Data Types\" width=\"551\" height=\"471\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1.png 551w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1-300x256.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1-150x128.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1-520x445.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/edit-img1-320x274.png 320w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">6: Make the changes in the code and execute it.<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96840\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2.png\" alt=\"VBA Code\" width=\"1415\" height=\"620\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2.png 1415w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-300x131.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-1024x449.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-150x66.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-768x337.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-720x315.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-520x228.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/vbe-img2-320x140.png 320w\" sizes=\"auto, (max-width: 1415px) 100vw, 1415px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Now, let\u2019s make use of a Dim statement in VBA to declare the variable. To declare a variable in the VBA. code editor is demonstrated below.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Variable()\r\nDim DataFlair As String\r\nDim articles as Integer\r\nEnd Sub<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Once the declaration is done, the variable reserves space in the memory to initialize the variable.<\/span><\/p>\n<h3>Using Variable in VBA<\/h3>\n<p><span style=\"font-weight: 400;\">The below code explains how to initialize a variable in VBA<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Initialize()\r\n    Dim articles As Integer\r\n    articles = 5\r\n    MsgBox articles\r\nEnd Sub<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">When you save and run the code, you get the following output:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96824\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op.png\" alt=\"VBA Data Types\" width=\"938\" height=\"454\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op.png 938w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op-300x145.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op-150x73.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op-768x372.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op-720x348.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op-520x252.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/initialise-op-320x155.png 320w\" sizes=\"auto, (max-width: 938px) 100vw, 938px\" \/><\/a><\/p>\n<h4>Declaring a Variable in VBA<\/h4>\n<p><span style=\"font-weight: 400;\">To declare a variable, follow the below steps:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1: Open an Excel workbook and save it as an Excel macro-enabled workbook.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2: <\/span><b>\u00a0<\/b><span style=\"font-weight: 400;\">Add a button using macros.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In order to create a macro,\u00a0<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Go to the Developer tab and click on insert from the ribbon.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Choose the command button.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Assign a macro by providing a name and click on the new button<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">3: Finally, press ok\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4: Once, the code window appears, type the following code.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sheet5_Button1_Click()\r\n\u00a0\u00a0\u00a0\u00a0Dim name As String, articles As Integer\r\n\u00a0\u00a0\u00a0\u00a0name = \"DataFlair\"\r\n\u00a0\u00a0\u00a0\u00a0articles = 2500\r\n\u00a0\u00a0\u00a0\u00a0Range(\"A1\") = name\r\n\u00a0\u00a0\u00a0\u00a0Range(\"A2\") = articles\r\nEnd Sub<\/pre>\n<p><span style=\"font-weight: 400;\">The user writes the code in the VBA editor. <\/span><span style=\"font-weight: 400;\">Your GUI appears as follows:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96825\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui.png\" alt=\"Variable GUI\" width=\"1309\" height=\"846\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui.png 1309w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-300x194.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-1024x662.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-150x97.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-768x496.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-720x465.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-520x336.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-gui-320x207.png 320w\" sizes=\"auto, (max-width: 1309px) 100vw, 1309px\" \/><\/a><\/p>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96826\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op.png\" alt=\"Variables in VBA\" width=\"1793\" height=\"849\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op.png 1793w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-300x142.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-1024x485.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-150x71.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-768x364.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-1536x727.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-520x246.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-720x341.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/var-op-320x152.png 320w\" sizes=\"auto, (max-width: 1793px) 100vw, 1793px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Before naming your variable, you have to ensure that:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1. The variable name is not a reserved keyword. Few reserved keywords are such as Dim, Private, Function, Loop etc.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Do not name your variable following a keyword.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3.\u00a0 Do not use special characters such as !, @, &amp;, ., #<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. Make sure there is no blank between a variable name.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5. The variable name should not exceed 255 characters in length.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6. A variable name cannot start with a number.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Some invalid variable names are 2day, user.name. <\/span><span style=\"font-weight: 400;\">Some valid variable names are: to_day, costprice.<\/span><\/p>\n<h3>Pros of Excel VBA Variable Type<\/h3>\n<p><span style=\"font-weight: 400;\">1. Using variables, the user can write structured VBA code.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Each variable has its capacity, limit, and application property.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Variables help the user to declare different types of data as per their requirement.<\/span><\/p>\n<h3>Data Types in VBA<\/h3>\n<p><span style=\"font-weight: 400;\">There are many data types that can be used in VBA. However, there are some common data types that you will be using more frequently. They are:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1. <strong>String<\/strong> \u2013 this data type stores the text values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. <strong>Boolean<\/strong> \u2013 this data type stores the TRUE or FALSE values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. <strong>Integer<\/strong> \u2013 this data type stores the whole number values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. <strong>Double<\/strong> \u2013 this data type stores the decimal values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5. <strong>Date<\/strong> \u2013 this data type stores the dates.<\/span><\/p>\n<p><strong>Note<\/strong>: <span style=\"font-weight: 400;\">You have to use quotation marks when the value is stored in string, date data type.\u00a0<\/span><\/p>\n<h4><b>Syntax:<\/b><\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim Variable_Name As DataType<\/pre>\n<h4>VBA String Data Type Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sheet6_Button1_Click()\r\nDim user_name As String\r\nuser_name = \u201cDataFlair\u201d\r\nMsgBox suser_name\r\nEnd Sub<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96828\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op.png\" alt=\"String Operator in VBA\" width=\"1800\" height=\"583\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op.png 1800w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-300x97.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-1024x332.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-150x49.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-768x249.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-1536x497.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-720x233.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-520x168.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/string-op-320x104.png 320w\" sizes=\"auto, (max-width: 1800px) 100vw, 1800px\" \/><\/a><\/p>\n<h4>Date Data Type Example<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sheet6_Button1_Click()\r\nDim start_date As Date\r\nstart_date = \"5\/5\/2021\"\r\nMsgBox start_date\r\nEnd Sub<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96829\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op.png\" alt=\"Date Operator in VBA\" width=\"1719\" height=\"994\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op.png 1719w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-300x173.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-1024x592.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-150x87.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-768x444.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-1536x888.png 1536w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-720x416.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-520x301.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/date-op-320x185.png 320w\" sizes=\"auto, (max-width: 1719px) 100vw, 1719px\" \/><\/a><\/p>\n<p><b>Boolean Data Type Example<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sheet5_Button1_Click()\r\nDim boolVar As Boolean\r\nboolVar = FTrue\r\nIf boolVar = True Then\r\n\u00a0\u00a0Range(\"A1\") = \"DataFlair Articles are Available\"\r\nElse\r\n\u00a0\u00a0Range(\"A1\") = \"There is No Article\"\r\nEnd If\r\nEnd Sub<\/pre>\n<p><span style=\"font-weight: 400;\">Once you save and run the code, you get the following output:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96830\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op.png\" alt=\"Bool Operator in VBA\" width=\"671\" height=\"413\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op.png 671w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op-300x185.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op-150x92.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op-520x320.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/bool-op-320x197.png 320w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/a><\/p>\n<p><b>Integer Data Type Example<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sheet6_Button1_Click()\r\nDim a As Integer\r\na = 650\r\nMsgBox a\r\nEnd Sub<\/pre>\n<p><span style=\"font-weight: 400;\">Once you save and run the code, you will get the following output:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96831\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op.png\" alt=\"Variables in VBA\" width=\"738\" height=\"462\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op.png 738w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op-300x188.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op-150x94.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op-720x451.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op-520x326.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/int-op-320x200.png 320w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/a><\/p>\n<p><b>Double Data Type Example<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sheet6_Button1_Click()\r\nDim a As IDouble\r\na = 17.2\r\nMsgBox a\r\nEnd Sub<\/pre>\n<p><span style=\"font-weight: 400;\">Once you save and run the code, you will get the following output:<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96832\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op.png\" alt=\"Double Data type in VBA\" width=\"1267\" height=\"842\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op.png 1267w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-300x199.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-1024x681.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-150x100.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-768x510.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-720x478.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-520x346.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-320x213.png 320w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/double-op-272x182.png 272w\" sizes=\"auto, (max-width: 1267px) 100vw, 1267px\" \/><\/a><\/p>\n<h4>VBA Data Types<\/h4>\n<table>\n<tbody>\n<tr>\n<td><b>Data Type<\/b><\/td>\n<td><b>Bytes<\/b><\/td>\n<td><b>Type<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Byte<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Integer<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Single<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Long<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Double<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Decimal<\/span><\/td>\n<td><span style=\"font-weight: 400;\">14 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Date<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Currency<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Object<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">String (Variable Length)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">10 bytes + Length of the string.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">String(Fixed Length)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Length of the string<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Variant(numbers)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">16 bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Variant(characters)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Length of the string + 22 Bytes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Non-Numeric<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">User-Defined<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Varies as per the data type<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8211;<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>How to declare a variant data type in VBA?<\/h3>\n<p><span style=\"font-weight: 400;\">We use variant data types when we are not sure about which data type to use. The variant data type cannot store fixed-length string data type alone.\u00a0<\/span><\/p>\n<p><b>Syntax:<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim myValue as Variant<\/pre>\n<h3>Using Option Explicit in VBA<\/h3>\n<p><span style=\"font-weight: 400;\">To go to options, click on the tools and choose options from the editor. Then, check the mark on the required variable declaration.<\/span><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96833\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1.png\" alt=\"options in VBA\" width=\"1393\" height=\"253\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1.png 1393w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-300x54.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-1024x186.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-150x27.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-768x139.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-720x131.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-520x94.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/options-1-320x58.png 320w\" sizes=\"auto, (max-width: 1393px) 100vw, 1393px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96834\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations.png\" alt=\"require variable declarations in VBA\" width=\"826\" height=\"618\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations.png 826w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations-300x224.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations-150x112.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations-768x575.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations-720x539.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations-520x389.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/require-variable-declarations-320x239.png 320w\" sizes=\"auto, (max-width: 826px) 100vw, 826px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Note<\/strong>: When we use Option Explicit in VBA, we can declare all the required variables.\u00a0<\/span><\/p>\n<h3>What is a Constant in VBA?<\/h3>\n<p><span style=\"font-weight: 400;\">A constant is more like a variable but it stores a value that cannot be changed.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The user uses the public keyword to declare constant in the public module level and private keyword to declare a private constant and this makes the code easier to read.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are two types of constant:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1. Intrinsic Constants\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. User Defined Constants\u00a0<\/span><\/p>\n<h4>Intrinsic Constants<\/h4>\n<p><span style=\"font-weight: 400;\">These are the constants provided by the application itself or we could say that the functions which are built-in are known as intrinsic constants.<\/span><\/p>\n<h4>User-Defined Constants in VBA<\/h4>\n<p><span style=\"font-weight: 400;\">These are the constants that are user-defined<\/span><\/p>\n<p><span style=\"font-weight: 400;\"> and created for their purposes. The user can create the constant by specifying a value to the declared constant.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Follow the rules to create a constant:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1. Declare the constant_name preceding with CONST.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Use the word \u201cAs\u201d to declare the DataType.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Assign the value to the variable with an equal to(=) sign.\u00a0<\/span><\/p>\n<p><b>Syntax:<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Const Constant_Name As Constant_DataType = Constant_Value<\/pre>\n<p><span style=\"font-weight: 400;\">Here, Constant_Name and Constant_Value are the required parameters and the Constant_DataType is an optional parameter.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The below code demonstrates how to declare a constant in VBA:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Constant()\r\nConst NumberofDays = 1\r\nMsgBox NumberofDays\r\nEnd Sub<\/pre>\n<p><b>Output:<\/b><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/const.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96835\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/const.png\" alt=\"VBA Data Types\" width=\"408\" height=\"284\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/const.png 408w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/const-300x209.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/const-150x104.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/const-320x223.png 320w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Before naming a constant, you have to ensure that:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">1. The first character is a letter in the constant name.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Do not use special characters such as !, @, &amp;, ., #<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. The name should not exceed 255 characters in length.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. The name is not a reserved keyword.\u00a0<\/span><\/p>\n<h4>Declaring a Constant in VBA<\/h4>\n<p><span style=\"font-weight: 400;\">You can also declare a constant as Private and this private constant can be accessed in its own module alone or if you can declare a constant as Public then it means that you can use it in other modules also.<\/span><\/p>\n<h3>Pros of Excel VBA Constants<\/h3>\n<p><span style=\"font-weight: 400;\">1. Declaring one or more variables as a constant would save a lot of time.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. This widely helps in reducing the lines of codes.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Once the constants are declared with the values and then whenever the user calls the constant, the value stored comes up.\u00a0<\/span><\/p>\n<h3>Cons of Excel VBA Constants<\/h3>\n<p><span style=\"font-weight: 400;\">Sometimes the user has to keep changing the value that is stored in constants if they are using it in different subcategories or classes.\u00a0<\/span><\/p>\n<h3>Summary<\/h3>\n<p><span style=\"font-weight: 400;\">Now, we have learnt how to declare a data type, constant and variable in VBA. We also know the differences between the variable and constant. Variables are used to store the value in computer memory. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Constants are very much useful to reduce the code lines. The constants are declared and assigned as per the user\u2019s convenience. There are also many data types and the data type tells about the type of the data.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This \u201cVBA Variables, Data Types &amp; Constants\u201d\u00a0 topic covers the concept of what variables and constants are. Knowing the difference between them and where to use them is really important.\u00a0 What is a Variable?&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":96819,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24129],"tags":[24548,24547,24549],"class_list":["post-96516","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ms-excel","tag-vba-constants","tag-vba-data-types","tag-vba-variables"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>VBA Data Types, Variables and Constants - DataFlair<\/title>\n<meta name=\"description\" content=\"VBA Variables are used to store pieces of data for use in macros and functions. These Variables are stored under many Data Types. Learn more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VBA Data Types, Variables and Constants - DataFlair\" \/>\n<meta property=\"og:description\" content=\"VBA Variables are used to store pieces of data for use in macros and functions. These Variables are stored under many Data Types. Learn more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-23T03:30:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Variables-Data-Types-Declare-VBA-Constants-in-Excel.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"VBA Data Types, Variables and Constants - DataFlair","description":"VBA Variables are used to store pieces of data for use in macros and functions. These Variables are stored under many Data Types. Learn more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/","og_locale":"en_US","og_type":"article","og_title":"VBA Data Types, Variables and Constants - DataFlair","og_description":"VBA Variables are used to store pieces of data for use in macros and functions. These Variables are stored under many Data Types. Learn more.","og_url":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-06-23T03:30:52+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Variables-Data-Types-Declare-VBA-Constants-in-Excel.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"VBA Data Types, Variables and Constants","datePublished":"2021-06-23T03:30:52+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/"},"wordCount":1323,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Variables-Data-Types-Declare-VBA-Constants-in-Excel.jpg","keywords":["VBA Constants","VBA Data Types","VBA Variables"],"articleSection":["MS Excel Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/","url":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/","name":"VBA Data Types, Variables and Constants - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Variables-Data-Types-Declare-VBA-Constants-in-Excel.jpg","datePublished":"2021-06-23T03:30:52+00:00","description":"VBA Variables are used to store pieces of data for use in macros and functions. These Variables are stored under many Data Types. Learn more.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Variables-Data-Types-Declare-VBA-Constants-in-Excel.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/06\/VBA-Variables-Data-Types-Declare-VBA-Constants-in-Excel.jpg","width":1200,"height":628,"caption":"VBA Variables, Data Types & Constants in Excel"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/vba-variables-data-types-constants\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"MS Excel Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/ms-excel\/"},{"@type":"ListItem","position":3,"name":"VBA Data Types, Variables and Constants"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=96516"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96516\/revisions"}],"predecessor-version":[{"id":96841,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96516\/revisions\/96841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/96819"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=96516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=96516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=96516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}