Ad space (banner)
Lesson 10 / 20

Working with arrays

This lesson covers the array, which handles several values together.

An array is declared as Dim name(count-1) As Type. Element indexes start at 0.

The sample code creates Dim fruits(2) As String — an array of three — assigns a fruit name to each, and then displays every element with a For statement.

A common early stumble is what Dim fruits(2) means. It means "indexes up to 2", so you actually get three elements: fruits(0), fruits(1), and fruits(2).

In professional work, reading several cells into an array first and then processing it runs considerably faster than reaching for each cell one at a time.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VBA directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)