Adding Control Statements

TYPE THIS:

Sub Build_Array()

Dim NewArray(1 To 3, 1 To 3) As Integer Dim K As Integer Dim L As Integer For K = 1 To 3

For L = 1 To 3 NewArray (K, L) = K+L Next L Next K End Sub

RESULT:

The code creates a two-dimensional array with values as outlined in the following table:

2

3

4

3

4

5

4

5

6

I Type Next to close the loop.

■ The For Each loop executes for each element in the specified array.

—Q Type For Each Element in Group, replacing Element with the variant variable declared and Group with the name of the array.

^0 Type the VBA code to execute as the body of the loop.

I Type Next to close the loop.

—, Type any additional statements for the subroutine.

— Switch to Excel and run the macro.

■ The For Each loop executes for each element in the specified array.

0 0

Post a comment