Dim myArray As Variant myArray = Worksheets("Sheet1").Range("B2:C17")

Although these two methods are quick and easy, they may not always suit the situation. What if you needed every other row in the array? The code to do this follows (see Figure 17.3):

Sub EveryOtherRow()

Dim i As Integer, j As Integer, myCount As Integer

'Fill the array with every other row For i = 1 To 8

myArray(i, j) = Worksheets("Sheet1").Cells(i * 2, j + 1).Value Next j Next i

'Empty the array

For myCount = LBound(myArray) To UBound(myArray) Worksheets("Sheet1").Cells(myCount * 2, 4) = _ WorksheetFunction.Sum(myArray(myCount, 1), myArray(myCount, Next myCount End Sub

Figure 17.3

Fill the array with only the data needed.

0 0

Post a comment