Article ID: 149831
Article Last Modified on 10/11/2006
Sub PopulateArrayThroughIteration()
' Dimension the variables.
Dim MyArray() As Integer
Dim cell As Object
Dim counter As Integer
' Set the value of the counter variable.
counter = 1
' Start the loop on the range.
For Each cell In Range("a1,a3:a20")
' Redimension the array, while preserving the previous
' elements using the counter variable.
ReDim Preserve MyArray(counter)
' Place a value into the array.
MyArray(counter) = cell.Value
' Increase counter by 1.
counter = counter + 1
' Loop.
Next cell
' Check a value to make sure the array is populated
' this should return 5.
MsgBox MyArray(4)
End Sub
Sub PopulateArrayContiguous()
Dim MyArray As Variant
' Populate the array.
MyArray = Range("a1:a20")
' Display a message box with a value in the array
' this should display a 5.
MsgBox MyArray(5, 1)
End Sub
For Each
For Each
Additional query words: 5.00a 5.00c 5.0 7.00a XL98 XL97 XL7 XL5 XL
Keywords: kbdtacode kbhowto kbprogramming KB149831