In this chapter, you will:

  • Learn how to declare an array

  • Fill an array

  • Retrieve data from an array

  • Use an array to speed up code

  • Use dynamic arrays

  • Pass an array to another procedure or function

An array is a type of variable that can be used to hold more than one piece of data. For example, if you have to work with the name and address of a client, your first thought might be to assign one variable for the name and another for the address of the client. Instead, consider using an array, which can hold both pieces of information—and not for just one client but for hundreds.

Declaring an array

You declare an array by adding parentheses after the array name and specifying the number of array elements in the parentheses:

Get Microsoft Excel 2019 VBA and Macros, First Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.