![excel visual basic excel visual basic](https://www.excel-easy.com/smi/vba/userform-2.png)
This declaration tells the VBA compiler that the array 'Team_Members' has 20 variables, which are referenced by indices 1 to 20. As seen above, a one-dimensional array can be declared as follows: Dim Team_Members(1 To 20) As String The above sections have already given some examples of Visual Basic Array declarations, but it is worth discussing this further. by adding further dimensions into the declaration and using a further index to reference the array entries.
![excel visual basic excel visual basic](https://reader020.dokumen.tips/reader020/slide/20190719/55c74b32bb61eb54448b4855/document-19.png)
You can declare arrays with 3 or more dimensions in the same way. For example, the sales figures for Team2 on January 15th would be referenced as: Jan_Sales_Figures(15, 2) In order to access the entries in the array 'Jan_Sales_Figures', you need to use two indices, refering to the day of the month and the team number.
![excel visual basic excel visual basic](https://images.saymedia-content.com/.image/c_limit%2Ccs_srgb%2Cq_auto:good%2Cw_700/MTc2MjY2MTk1MjIwOTY0NTI1/how-to-write-visual-basic-code-to-configure-a-user-interface-created-using-a-userform-in-excel-2007-and-excel-2010.png)
You would then declare the array as follows: Dim Jan_Sales_Figures(1 To 31, 1 To 5) As Currency You would need a 2-dimensional array, consisting of 5 sets of figures over 31 days. An array having two dimensions can be thought of as a grid of values.įor example, imagine that you want to store daily sales figures for the month of January, for 5 different teams. However, arrays can have multiple dimensions. The Visual Basic Arrays discussed above are one-dimensional, in that they refer to one list of Names. Multi-Dimensional Excel Visual Basic Arrays Cells(i, 1).Value = Team_Members(i) Next iĮven with just 20 names, the advantages of using an Array are clear, but imagine if you had 1,000 names to store! And imagine you wanted to store Surnames separately from Forenames! It would soon become almost impossible to handle this amount of data without the use of Arrays in your VBA code.