VBA arrays definition in Excel

Arrays are tantamount to variables except that, they store more than one value

Array size defines the number of values it can store at the most

Array index always starts from 0

If Array size is 4, then the index ranges from 0 to 4.

Declaration of Arrays

  1. Sub Array_demo()
  2. 'Method 1 : Specifying the size
  3. Dim array_example1(4)
  4. 'Method 2 : Using the Array function
  5. Dim array_example_2
  6. array_example_2 = Array("Value1", "Value2", "Value3")
  7. 'Assigning Values to Array
  8. array_example1(0) = "Value1"
  9. array_example1(1) = "Value2"
  10. array_example1(2) = "Value3"
  11. array_example1(3) = "Value4"
  12. array_example1(4) = "Value5"
  13. End Sub

Here is how it looks like in the editor

excel vba arrays definition


You can find similar Excel Questions and Answer hereunder

1) I track a stock on a daily basis and enter the Open, High, Low and Close values for every trading day. In Excel, how can I automatically get High and Low values for the last 10 trading days?

2) Tables in Excel VBA. How you can create table in VBA and work with them with macros

3) I have 2 sets of lists from 2 different reports - how can I select the cells with differences?

4) Vba length of an array in Excel

5) How to convert a type of data into another type of date, how to convert a string to an integer or a integer nto a string

6) How do I get the 2nd highest number in a range of numbers?

7) Here we show you advanced VBA array functions, like splitting arrays, Lbound, Ubound

8) Is there a way I can easily identify the duplicate values in a dataset?

9) I have a large list of clients whose current Age I need to maintain in my database as it influences costs - how can I have Excel display the current age at all times?

10) Can I add a small chart to Table data to make it visually appealing and easy to interpret?


Here the previous and next chapter