

{"id":100579,"date":"2021-10-06T09:00:41","date_gmt":"2021-10-06T03:30:41","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=100579"},"modified":"2021-10-06T11:50:56","modified_gmt":"2021-10-06T06:20:56","slug":"excel-vba-arrays","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/","title":{"rendered":"Excel VBA Arrays"},"content":{"rendered":"<p>An array can store one or more values in memory and the values should be of the same data type. The elements of an array are the individual values in the collection of an array. They are stored in a continuous order indexing from 0 to nth value. Now, let&#8217;s see the types, advantages of the vba array in excel.<\/p>\n<h3>Advantages of VBA array:<\/h3>\n<p>VBA array function\u2019s benefits:<\/p>\n<p><strong>1. Grouping logically related data<\/strong><\/p>\n<p>If you are storing a list of groceries such as fruits, vegetables etc. Then, you can use a single array variable that has a separate location for categories i.e., vegetables, fruits.<\/p>\n<p><strong>2. Easy to maintain the codes<\/strong><\/p>\n<p>It\u2019s easy to maintain the code because defining a single variable is enough, instead of defining more than one variable.<\/p>\n<p><strong>3. Better performance<\/strong><\/p>\n<p>Retrieving, sorting, and modifying the data in an array are faster.<\/p>\n<h3>Array Types in VBA:<\/h3>\n<p>There are two types of arrays and those are:<\/p>\n<p><strong>1. Static<\/strong> \u2013 Static type array will have a fixed number of elements and it can\u2019t be changed further. These kinds of arrays are efficient when the user is working with the fixed entities. Some of the examples of static arrays are Gender, Number of months in a year, Number of days in a week etc.<\/p>\n<p><strong>Static array syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim arrayName (n) as datatype\r\n<\/pre>\n<p>This syntax declares an array name with the size of n variables and the data type refers to the type of data in an array.<br \/>\n<strong><strong>Example:<\/strong><\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim ArrayGender(3) As String\r\n<\/pre>\n<p><strong>2. Dynamic<\/strong> \u2013 Dynamic type of an array will not have a fixed number of elements and it can be changed further also. These kinds of arrays are useful when the user is not sure about the size of the entities. Some of the examples of dynamic array are employee_id, color_names<\/p>\n<p><strong>Dynamic array syntax<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim arrayName() as datatype\r\nReDim arrayName(4)\r\n<\/pre>\n<p>This \u201cDim arrayName() as datatype\u201d syntax declares an array with a name and the data type. \u201cReDim arrayName(4)\u201d declares the array size.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim ArrayEmployee() As Variant\r\n<\/pre>\n<h3>VBA Array Declaration<\/h3>\n<p>An array variable uses parenthesis while declaration but otherwise the declaration of an array variable is the same as the other variables. There are three methods to declare an array:<\/p>\n<h4>Method 1: Variant Arrays<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim arrEmployees()\r\n<\/pre>\n<p>In this method, we are declaring an array without mentioning the size. With a variant type array, the user need not define an array size.<\/p>\n<h4>Method 2: Non &#8211; Variant Arrays<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim arrEmployees()\r\nDim arrEmployees() A s String\r\nReDim arrEmployees(1 to 100)\r\nEnd Sub\r\n<\/pre>\n<p>With non-variant arrays, the user can define the array size before assigning the values to the array. Here, the user uses the ReDim command to set the size of an array.<\/p>\n<h4>Method 3: Static Array<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Dim arrEmployees(100)\r\n<\/pre>\n<p>In this method, we are declaring an array mentioning the array size of 100. Although the array size is 100, it can hold 101 data values as array index starts from 0.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li>Array Index cannot be less than 0 or it cannot be negative.<\/li>\n<li>VBA arrays can store any type of variable in it. A single array variable can store any data type variable such as integer, string, characters etc.<\/li>\n<\/ul>\n<h3>VBA Array Function<\/h3>\n<p>The user can quickly initialize an array in Excel VBA. The user can also change the starting index number. By default, the index number starts from 0 but the user can change it to 1 or some other number as per their convenience. In order to change the index number, you have to add option base 1 to the general declarations section.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Option Explicit\r\nOption Base 1\r\nSub Button1_Click()\r\nDim DataFlair As Variant\r\nDataFlair = Array(\"VBA Article\", \"Python Article\", \"Java Article\")\r\nMsgBox DataFlair(1)\r\n \r\nEnd Sub\r\n<\/pre>\n<p>Save and run the code, you will get the following <strong>output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/arr-func-op.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102154\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/arr-func-op.png\" alt=\"vba array output\" width=\"1317\" height=\"838\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/arr-func-op.png 1317w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/arr-func-op-768x489.png 768w\" sizes=\"auto, (max-width: 1317px) 100vw, 1317px\" \/><\/a><\/p>\n<h3>Assigning Values to an Array<\/h3>\n<p>Each data value in the array is assigned by an array index value. It can also be a string.<\/p>\n<p><strong>Sample Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Private Sub Employees_Click()\r\n   Dim arrEmp(0 to 2) as String  \r\n     arrEmp(0) = \"Deepak\" \r\n     arrEmp(1) = \"Anush\" \r\n     arrEmp(2) = \"Krish\"\r\n End Sub\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><br \/>\nHere, the code assign=s values to the elements in the array. The 0 th index is occupied by Deepak, 1st index is occupied by Anush and the 2nd index in the array is occupied by Krish. This is how a user can assign values in an array.<\/p>\n<h3>Multi-Dimensional Arrays in Excel VBA<\/h3>\n<p>Apart from single arrays, there are also multidimensional arrays and the most commonly used one is two-dimensional arrays. An array can contain a maximum of 60 dimensions.<\/p>\n<p><strong>Example<\/strong><br \/>\nIn the following example, a multi-dimensional array is declared with 2 rows and 5 columns.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Private Sub Employees_Click()\r\n   Dim arr(2,5) as Variant\t    \r\n   arr(0,0) = \"Deepti\" \r\n   arr(0,1) = \"Akkshaya\"\r\n   arr(0,2) = \"Guhanesvar\"           \r\n   arr(0,3) = \"Swetha\" \r\n   arr(0,4) = \"Ram\"\r\n   arr(1,0) = \"Hari\"           \r\n   arr(1,1) = \"Sanchez\"           \r\n   arr(1,2) = \"Aarya\"           \r\n   arr(1,3) = \"Sri\"\r\n   arr(1,4) = \"Akshra\"           \r\n   msgbox(\" The employee data in the Array index 0,1 : \" &amp;  arr(0,1))\r\n   msgbox(\"The employee data in the Array index 1,2 : \" &amp;  arr(1,2))\r\nEnd Sub\r\n<\/pre>\n<p>When you execute the function, the following <strong>output<\/strong> appears.<br \/>\nValue stored in Array index : 0 , 1 : Akkshaya<br \/>\nValue stored in Array index : 1 , 2 : Aarya<\/p>\n<h3>ReDim Statement in VBA<\/h3>\n<p>To declare dynamic-array variables, we use the ReDim statement. Using the redim statement, we can also allocate or reallocate the storage spaces.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ReDim [Preserve] variable_name(boundlist) [, variable_name(boundlist)]\r\n<\/pre>\n<p><strong>Parameter Description<\/strong><\/p>\n<ul>\n<li><strong>Preserve<\/strong> \u2212 When the user changes the size of the dimension, this parameter preserves the data values stored in the existing arrays. It is one of the optional parameters.<\/li>\n<li><strong>Variable_name<\/strong> \u2212 It is one of the required parameters and this denotes the name of the variable. This variable name should follow the standard variable naming conventions.<\/li>\n<li><strong>Boundlist<\/strong> \u2212 It is one of the required parameters and this parameter indicates the size of an array.<\/li>\n<\/ul>\n<p><strong>Example<\/strong><br \/>\nLet\u2019s see an example where we change the array dimension and still preserve the existing data values in the array.<\/p>\n<p>Note: The data from the array will be lost if we resize the array size to a smaller size from its original size.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Private Sub Employees_Click()\r\n   Dim a() as variant\r\n   i = 0\r\n   redim a(5)\r\n   a(0) = \"Sheetal\"\r\n   a(1) = \u201cPragya\u201d\r\n   a(2) = \u201cSrithika\u201d\r\n  \r\n   REDIM PRESERVE a(7)\r\n   For i = 3 to 7\r\n   a(i) = \u201cDataFlair Employees\u201d\r\n   Next\r\n  \r\n   'to Fetch the output\r\n   For i = 0 to ubound(a)\r\n      Msgbox a(i)\r\n   Next\r\nEnd Sub\r\n<\/pre>\n<p>When you execute the above function, it produces the following <strong>output.<\/strong><\/p>\n<p>Sheetal<br \/>\nPragya<br \/>\nSrithika<br \/>\nDataFlair Employees<br \/>\nDataFlair Employees<br \/>\nDataFlair Employees<br \/>\nDataFlair Employees<br \/>\nDataFlair Employees<\/p>\n<h3>Array Methods<\/h3>\n<p>Within VBScript, there are many inbuilt functions available and these functions help the users to develop arrays effectively. The below list are the methods that are used in conjunction with arrays.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Function<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Upper bound<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This function returns an integer that corresponds to the largest subscript of the array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Lower Bound<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This function returns an integer that corresponds to the smallest subscript of the array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Split<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This function returns an array that contains a specified number of values.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Join<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This function returns a string that contains a specified number of substrings in an array.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Filter<\/span><\/td>\n<td><span style=\"font-weight: 400;\">On a specific filter criteria, this function returns an array that contains the subset of the string.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">IsArray<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This function returns a boolean value which indicates whether the input variable is an array or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Erase<\/span><\/td>\n<td><span style=\"font-weight: 400;\">This function recovers the memory which has been allocated for the particular array variables.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Dimensions of an Array:<\/h3>\n<p>An array can be of 1d, 2d or multidimensional.<\/p>\n<p><strong>1. One dimensional array:<\/strong> When you use only one index in the array, then those arrays are known as one dimensional arrays. For example, a list of grades.<\/p>\n<h4>Example of One Dimensional Array<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Button1_Click()\r\nDim Grades(1 To 5) As String\r\nGrades(1) = a\r\nGrades(2) = b\r\nGrades(3) = C\r\nGrades(4) = D\r\nGrades(5) = F\r\nMsgBox (Grades(1))\r\nEnd Sub\r\n<\/pre>\n<p>When you save and run the code, you get the following <strong>output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/1d-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102155\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/1d-output.png\" alt=\"1d array\" width=\"1233\" height=\"772\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/1d-output.png 1233w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/1d-output-768x481.png 768w\" sizes=\"auto, (max-width: 1233px) 100vw, 1233px\" \/><\/a><\/p>\n<p><strong>2. Two dimensional array:<\/strong> When you use two indexes in an array, then those arrays are known as two dimensional arrays. For example, the number of employees in each department. It requires a number of departments and the number of employees in each department.<\/p>\n<h4>Example of Two Dimensional Array:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub twodim()\r\nDim TwoDimension(1 To 2, 1 To 2) As Long\r\nDim i As Integer\r\nDim j As Integer\r\n\r\n\r\nTwoDimension(1, 1) = 2016\r\nTwoDimension(1, 2) = 2017\r\nTwoDimension(2, 1) = 500\r\nTwoDimension(2, 2) = 556\r\n\r\nFor i = 1 To 2\r\n    For j = 1 To 2\r\n        Cells(i, j) = TwoDimension(i, j)\r\n    Next j\r\nNext i\r\n\r\nEnd Sub\r\n<\/pre>\n<p>When you save and run the code, you will get the following <strong>output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/two-dimension.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102156\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/two-dimension.png\" alt=\"two dimension vba array\" width=\"1319\" height=\"977\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/two-dimension.png 1319w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/two-dimension-768x569.png 768w\" sizes=\"auto, (max-width: 1319px) 100vw, 1319px\" \/><\/a><\/p>\n<p><strong>3. Multi-dimensional array:<\/strong> When you use more than two indexes then those arrays are known as multi dimensional arrays. For example, selling price, cost price, discounted price of a product.<\/p>\n<h4>Example of VBA Multi-Dimensional Array<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Multi_Dimensional()\r\nDim MultiDimension(1 To 3, 1 To 2) As Long\r\nDim i As Integer\r\nDim j As Integer\r\n\r\nMultiDimension(1, 2) = 2016\r\nMultiDimension(2, 1) = 500\r\nMultiDimension(1, 1) = 2017\r\nMultiDimension(2, 2) = 556\r\nMultiDimension(3, 1) = 2018\r\nMultiDimension(3, 2) = 680\r\n\r\nFor i = 1 To 3\r\n    For j = 1 To 2\r\n        Cells (i, j) = MultiDimension (i,  j)\r\n    Next j\r\nNext i\r\n\r\nEnd Sub\r\n<\/pre>\n<p>When you save and run the code, you will get the following <strong>output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/multidimension.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102157\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/multidimension.png\" alt=\"multidimension\" width=\"917\" height=\"833\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/multidimension.png 917w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/multidimension-768x698.png 768w\" sizes=\"auto, (max-width: 917px) 100vw, 917px\" \/><\/a><\/p>\n<h3>How to use an array in VBA?<\/h3>\n<p>To make use of arrays in vba excel, follow the steps:<\/p>\n<p><strong>Step 1 :<\/strong> Open an excel workbook and save it as excel macro-enabled workbook (*.xlsm)<\/p>\n<p><strong>Step 2 :<\/strong> Add a button using macros.<\/p>\n<ul>\n<li>In order to create a macro, go to the developer tab and click on insert from the ribbon.<\/li>\n<li>Choose the command button.<\/li>\n<li>Assign a macro by providing a name and click on the new button<\/li>\n<\/ul>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/assigning-a-macro.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102158\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/assigning-a-macro.png\" alt=\"assigning a macro\" width=\"550\" height=\"475\" \/><\/a><\/p>\n<p><strong>Step 3:<\/strong> Finally, press ok<\/p>\n<p><strong>Step 4:<\/strong> Once, the code window appears, type the following code.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub DataFlair_Click()\r\n    Dim names(1 To 4) As String\r\n \t\tnames(1) = \"Anant\"\r\n        names(2) = \"Sheetal\"\r\n        names(3) = \"Linda\"\r\n        names(4) = \"Himtaj\"\r\n \r\n        Sheet1.Cells(1, 1).Value = \"Employees\"\r\n    Sheet1.Cells(2, 1).Value = names(1)\r\n    Sheet1.Cells(3, 1).Value = names(2)\r\n    Sheet1.Cells(4, 1).Value = names(3)\r\n    Sheet1.Cells(5, 1).Value = names(4)\r\n End Sub\r\n<\/pre>\n<p>Here, \u201cDim names(1 To 4) As String\u201d declares an array variable called names with 1 to 4 index.<\/p>\n<p>Here, these statements, \u2018names(1) = &#8220;Anant&#8221;<\/p>\n<p>names(2) = &#8220;Sheetal&#8221;<\/p>\n<p>names(3) = &#8220;Linda&#8221;<\/p>\n<p>names(4) = &#8220;Himtaj&#8221;\u2019 declares the value to each element in an array.<\/p>\n<p>Here, these statements, \u2018Sheet1.Cells(1, 1).Value = &#8220;Employees&#8221;<\/p>\n<p>Sheet1.Cells(2, 1).Value = names(1)<\/p>\n<p>Sheet1.Cells(3, 1).Value = names(2)<\/p>\n<p>Sheet1.Cells(4, 1).Value = names(3)<\/p>\n<p>Sheet1.Cells(5, 1).Value = names(4)\u2019 assigns employees to the first cell in the spreadsheet and each value in the array follows<\/p>\n<p>the reference and falls in order.<\/p>\n<p><strong>Step 5:<\/strong> Click on save button or press ctrl+s<\/p>\n<p><strong>Step 6:<\/strong> Close the vba code editor window<\/p>\n<p>Your GUI appears as follows:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/df-button.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102159\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/df-button.png\" alt=\"df button\" width=\"433\" height=\"232\" \/><\/a><\/p>\n<p>Once you click on the button, you will get the following <strong>output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/clicking-on-button.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102160\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/clicking-on-button.png\" alt=\"clicking on button\" width=\"878\" height=\"639\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/clicking-on-button.png 878w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/clicking-on-button-768x559.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/a><\/p>\n<h3>VBA Array Length<\/h3>\n<p>The length of an array is known as array length.The function used in excel VBA to get an array length is Lbound and Ubound. The data in the array are a set of elements in two dimensions. We use arrays in day- to-day lives and so knowing the array length is one of the essentials while working on the arrays. The full form of Lbound and Ubound are lower bound and Upper bound. The function arr.length also helps in finding the array length.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/arrays.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102162\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/arrays.png\" alt=\"arrays\" width=\"450\" height=\"366\" \/><\/a><\/p>\n<p>Above is an array with six rows and two columns. Now let\u2019s see how to find the length of this array.<\/p>\n<p>Note: Before finding an array length, make sure that the developer\u2019s tab is enabled.<\/p>\n<h3>How to Use Excel VBA Array Length?<\/h3>\n<p>To find the VBA Array length, follow the steps:<\/p>\n<p>Step 1: Go to the developer tab and click on the visual basic icon.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102163\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic.png\" alt=\"visual basic\" width=\"1233\" height=\"171\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic.png 1233w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic-768x107.png 768w\" sizes=\"auto, (max-width: 1233px) 100vw, 1233px\" \/><\/a><\/p>\n<p>Step 2: The VBA editor opens up and inside it, go to the insert tab and choose the module option.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102164\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module.png\" alt=\"VBA module\" width=\"778\" height=\"253\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module.png 778w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module-768x250.png 768w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/a><\/p>\n<p>Note: A new code window opens up.<\/p>\n<p>Step 3: Write the code by declaring a sub function and an array as integer.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Sample()\r\nDim Employees(1 To 10, 1 To 2) As String, x As Integer, y As Integer\r\nx = UBound(Employees, 1) - LBound(Employees, 1) + 1\r\ny = UBound(Employees, 2) - LBound(Employees, 2) + 1\r\nMsgBox \"The array declared has \" &amp; x * y &amp; \" Data values in it.\"\r\nEnd Sub\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><br \/>\nHere, we have declared the array as employees with two integer variables. We have also mentioned the upper limit and lower limit to the array and finally we are displaying the size of the array from the code.<\/p>\n<p>Step 7: Save and run the code.<\/p>\n<p>The following <strong>output<\/strong> appears:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/array-output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102165\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/array-output.png\" alt=\"vba array output\" width=\"928\" height=\"431\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/array-output.png 928w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/array-output-768x357.png 768w\" sizes=\"auto, (max-width: 928px) 100vw, 928px\" \/><\/a><\/p>\n<p>There are a total of 20 data with 10 rows and 2 columns.<\/p>\n<h3>Things to Remember<\/h3>\n<ul>\n<li>Declare the array first to find the array length.<\/li>\n<li>Lbound and Ubound are much helpful to find the length of an array.<\/li>\n<li>The data in the array are a set of elements in two dimensions.<\/li>\n<\/ul>\n<h3>Advantages of an Array in VBA<\/h3>\n<ul>\n<li>Array groups the logically related data together.<\/li>\n<li>The array makes it much easier to write code.<\/li>\n<li>Arrays give better and more effective performance. Once the array is created, it is easy to sort, retrieve and modify the data.<\/li>\n<\/ul>\n<h3>ArrayList in VBA<\/h3>\n<p>ArrayList is a list of an array with nearby memory location and the values in the array are retrieved using the index numbers. The index of an array list starts from 0 and the indexing value continues such as 1,2,3&#8230;.<\/p>\n<p>ArrayList also contains many inbuilt operations such as sorting, adding, removing, reversing etc. ArrayList is not a part of VBA, it is an external library which can be accessed with VBA. Excel arraylist are dynamic compared to the normal arrays.<\/p>\n<h3>How to add the library:<\/h3>\n<p>To include the library \u201cmscorlib.dll\u201d, follow the steps:<\/p>\n<p>1: Go to the VBA editor and choose tools from the main menu.<\/p>\n<p>2: Choose the references option as it contains the libraries.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/references.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102166\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/references.png\" alt=\"references\" width=\"884\" height=\"499\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/references.png 884w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/references-768x434.png 768w\" sizes=\"auto, (max-width: 884px) 100vw, 884px\" \/><\/a><\/p>\n<p>3: The list of libraries appears and choose \u201cmscorlib.dll\u201d, tick mark on the checkbox and press ok button.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/library.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102167\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/library.png\" alt=\"library\" width=\"735\" height=\"404\" \/><\/a><\/p>\n<p>Finally, the ArrayList is added to the VBA code.<\/p>\n<p><strong>Example of excel VBA ArrayList<\/strong><\/p>\n<p>Sorting ArrayList Using VBA Code<\/p>\n<p>Follow the steps to sort the arraylist:<\/p>\n<p>Step 1: Go to the developer tab and click on the visual basic icon.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102163\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic.png\" alt=\"visual basic\" width=\"1233\" height=\"171\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic.png 1233w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/visual-basic-768x107.png 768w\" sizes=\"auto, (max-width: 1233px) 100vw, 1233px\" \/><\/a><\/p>\n<p>Step 2: The VBA editor opens up and inside it, go to the insert tab and choose the module option.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102164\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module.png\" alt=\"VBA module\" width=\"778\" height=\"253\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module.png 778w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/module-768x250.png 768w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/a><\/p>\n<p>Note: A new code window opens up.<\/p>\n<p>Step 3: Write the code by declaring a sub function to perform the sorting to the provided data values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub datasort()\r\nDim datasort As ArrayList\r\nSet datasort = New ArrayList\r\ndatasort.Add \"100\"\r\ndatasort.Add \"60\"\r\ndatasort.Add \"80\"\r\ndatasort.Add \"90\"\r\ndatasort.Add \"20\"\r\ndatasort.Add \"40\"\r\ndatasort.Add \"10\"\r\ndatasort.Add \"30\"\r\ndatasort.Add \"70\"\r\ndatasort.Add \"50\"\r\ndatasort.Sort\r\n \r\nMsgBox (datasortsort(0) &amp; vbCrLf &amp; datasort(1) _\r\n&amp; vbCrLf &amp; datasort(2) &amp; vbCrLf &amp; datasort(3) _\r\n&amp; vbCrLf &amp; datasort(4) &amp; vbCrLf &amp; datasort(5) _\r\n&amp; vbCrLf &amp; datasort(6) &amp; vbCrLf &amp; datasort(7) _\r\n&amp; vbCrLf &amp; datasort(8) &amp; vbCrLf &amp; datasort(9) _\r\n&amp; vbCrLf &amp; datasort(10))\r\nEnd Sub\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><br \/>\nDeclare a sub function to perform sorting. We have added the arraylist as an object to the function and a new instance is set to this object. Using the add method, we can insert the elements to the arraylist and we have applied the sort property to sort the list using sort method. By default, the lists are sorted in ascending order. We use vbCrLf to print the data values one by one in a new line. Finally, we use the message box to print the sorted list.<\/p>\n<p>Step 4: Save and run the file.<\/p>\n<p>The following <strong>output<\/strong> appears:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/sorted-array.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102168\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/sorted-array.png\" alt=\"sorted array\" width=\"940\" height=\"350\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/sorted-array.png 940w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/sorted-array-768x286.png 768w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/a><\/p>\n<p>Testing the Application<\/p>\n<p>Step 1: Go to the Developer tab.<\/p>\n<p>Note: Check whether the design mode is on or off. If it is on, then the application wouldn\u2019t work.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-off.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102170\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-off.png\" alt=\"design mode off\" width=\"1920\" height=\"197\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-off.png 1920w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-off-768x79.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-off-1536x158.png 1536w\" sizes=\"auto, (max-width: 1920px) 100vw, 1920px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Step 2: Click on the Design Mode to turn it off.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-on.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102169\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-on.png\" alt=\"design mode on\" width=\"1749\" height=\"198\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-on.png 1749w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-on-768x87.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/design-mode-on-1536x174.png 1536w\" sizes=\"auto, (max-width: 1749px) 100vw, 1749px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Step 3: Click on the newly created button.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/test-app.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102171\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/test-app.png\" alt=\"test app\" width=\"1694\" height=\"990\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/test-app.png 1694w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/test-app-768x449.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/test-app-1536x898.png 1536w\" sizes=\"auto, (max-width: 1694px) 100vw, 1694px\" \/><\/a><\/p>\n<p>The following <strong>output<\/strong> appears.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/output.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-102172\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/output.png\" alt=\"output\" width=\"952\" height=\"493\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/output.png 952w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/10\/output-768x398.png 768w\" sizes=\"auto, (max-width: 952px) 100vw, 952px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Using VBA Array and Split Function<\/h3>\n<p>The user can use the Array function to fill the array with a list of items. The user can declare the array as a variant type. Here is a sample code using the split function.<\/p>\n<p>By default, the array function will start at zero index. The user can use the split function to split a string into an array based on a delimiter. A comma or space is a delimiter character which separates the items.<\/p>\n<p>The following code will split the string into an array of three elements:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Sub Articles()\r\nDim s As String\r\nDim arr() As String\r\ns = \"Excel, Python, Java\"\r\narr = Split(s, \",\")\r\nMsgBox (arr)\r\nEnd Sub\r\n<\/pre>\n<p><strong>Code Explanation:<\/strong><br \/>\nHere, the s string is split into array elements. The delimiter character comma is used to separate the items using split function. The separated items are stored in the arr variable which is also a string data type.<\/p>\n<h3>Using Erase with the VBA Array<\/h3>\n<p>The user uses the erase function on arrays to delete the items in an array or an array.<\/p>\n<p>The erase function resets all the values by default in a static array. The value is set to zero if the array is made up of long integers. If the array is made up of string then they are converted to \u201c \u201d.<\/p>\n<p>In a dynamic array, the memory is deallocated using the erase function. If the user wanted to use the array again then the ReDim keyword should be used to allocate the memory.<\/p>\n<p>Let\u2019s have a look at a sample.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Private Sub CommandButton1_Click()\r\nDim articles(0 To 2) As Integer\r\n   articles(0) = 235\r\n   articles(1) = 123\r\n   articles(2) =  99\r\n Erase articles\r\n    Debug.Print \"Location\", \"Value\"\r\n    For i = LBound(articles) To UBound(articles)\r\n        Debug.Print i, articles(i)\r\n    Next i\r\nEnd Sub\r\n<\/pre>\n<p>Here, the user assigns string value to each array element in an array. The erase function erases all the values in the array and sets the array value back to zero.<\/p>\n<h3>Summary:<\/h3>\n<ul>\n<li>An array is a variable which stores more than one value.<\/li>\n<li>Excel VBA arrays are classified into static and dynamic arrays.<\/li>\n<li>Arrays can hold more than one value of the same data type.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>An array can store one or more values in memory and the values should be of the same data type. The elements of an array are the individual values in the collection of an&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":102105,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24129],"tags":[25125,25126,25129,25127,25124,25128],"class_list":["post-100579","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ms-excel","tag-advantages-of-array-in-vba","tag-array-types-in-vba","tag-redim-statement","tag-static-array-in-vba","tag-vba-array","tag-vba-array-declaration"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Excel VBA Arrays - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what are arrays in VBA, VBA Array Types and advantages, Array Declaration, ReDim Statement in VBA, Array Length, ArrayList etc.\" \/>\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\/excel-vba-arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Excel VBA Arrays - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what are arrays in VBA, VBA Array Types and advantages, Array Declaration, ReDim Statement in VBA, Array Length, ArrayList etc.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/\" \/>\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-10-06T03:30:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-06T06:20:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/Excel-vba-array.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=\"15 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Excel VBA Arrays - DataFlair","description":"Learn what are arrays in VBA, VBA Array Types and advantages, Array Declaration, ReDim Statement in VBA, Array Length, ArrayList etc.","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\/excel-vba-arrays\/","og_locale":"en_US","og_type":"article","og_title":"Excel VBA Arrays - DataFlair","og_description":"Learn what are arrays in VBA, VBA Array Types and advantages, Array Declaration, ReDim Statement in VBA, Array Length, ArrayList etc.","og_url":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-10-06T03:30:41+00:00","article_modified_time":"2021-10-06T06:20:56+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/Excel-vba-array.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":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/b49855299264df5e27e3ec6c2cd9fde9"},"headline":"Excel VBA Arrays","datePublished":"2021-10-06T03:30:41+00:00","dateModified":"2021-10-06T06:20:56+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/"},"wordCount":2396,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/Excel-vba-array.jpg","keywords":["Advantages of Array in VBA","Array Types in VBA","ReDim Statement","Static Array in VBA","VBA Array","VBA Array Declaration"],"articleSection":["MS Excel Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/","url":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/","name":"Excel VBA Arrays - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/Excel-vba-array.jpg","datePublished":"2021-10-06T03:30:41+00:00","dateModified":"2021-10-06T06:20:56+00:00","description":"Learn what are arrays in VBA, VBA Array Types and advantages, Array Declaration, ReDim Statement in VBA, Array Length, ArrayList etc.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/Excel-vba-array.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/09\/Excel-vba-array.jpg","width":1200,"height":628,"caption":"Excel vba array"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/excel-vba-arrays\/#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":"Excel VBA Arrays"}]},{"@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\/b49855299264df5e27e3ec6c2cd9fde9","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ef46b745ddad2fad690af626c6ef29b91809ad0a9f5ef398d07817d8cad042f5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team is a group of passionate educators and industry experts dedicated to providing high-quality online learning resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With years of experience in the field, the team aims to simplify complex topics and help learners advance their careers. At DataFlair, we believe in empowering students and professionals with the knowledge and skills needed to thrive in today\u2019s fast-paced tech industry. Follow us for Free courses, expert insights, tutorials, and practical tips to boost your learning journey.","url":"https:\/\/data-flair.training\/blogs\/author\/datafbdad\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100579","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=100579"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100579\/revisions"}],"predecessor-version":[{"id":103225,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/100579\/revisions\/103225"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/102105"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=100579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=100579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=100579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}