Pages

Friday, February 17, 2012

Store worksheet range in a array

If you want to save the worksheet range in a array .

Here is the code-

Example 1

Sub save_worksheet_range_in_array1()
' single dimension
' declare abc as variant
Dim abc As Variant
' store a range in array
abc = Range("a1:a6")
For j = LBound(abc) To UBound(abc)
MsgBox abc(j, 1)
Next
End Sub


Example 2

Sub save_worksheet_range_in_array2()
' two and more dimension
' declare abc as variant
Dim abc As Variant
' store a range in array
abc = Range("a1:b6")
For j = LBound(abc) To UBound(abc)
MsgBox abc(j, 1)
MsgBox abc(j, 2)
Next
End Sub


Example 3

Sub save_worksheet_range_in_array3()
' two and more dimension
' declare abc as variant
Dim abc As Variant
' store a range in array
abc = Range("a1:c6")
For j = LBound(abc) To UBound(abc)
MsgBox abc(j, 1)
MsgBox abc(j, 2)
MsgBox abc(j, 3)
Next
End Sub

No comments:

Post a Comment