I have a variant array and i define it initially like the following:
test_array = ws.Range("A1:A26").Value
I want to "clear" the contents of the array and start over populating it with other values. But i want the qty of entries in the array to stay the same.....and the data type as well.
Option Base 1
Sub test1()
Dim fl_name As String
Dim test_array As Variant
fl_name = ThisWorkbook.Name
Set ws = Workbooks(fl_name).Worksheets("Sheet1")
test_array = ws.Range("A1:A26").Value
junk1 = UBound(test_array)
For intIndex = 1 To UBound(test_array)
Debug.Print test_array(intIndex, 1);
Next
Debug.Print
ReDim test_array(junk1) As Variant
For intIndex = 1 To UBound(test_array)
Debug.Print test_array(intIndex, 1);
Next
Debug.Print
End Sub
i tried the following code but when it gets to the "2nd" For statement i get a run time error.
I found this code to clear the array on line. The code used a slightly different array type but i thought i could still use this with my variant type array. Her eis the orringal code which does not crash.
Sub test()
Dim intArray() As Integer
Dim intIndex As Integer
ReDim intArray(3) As Integer
intArray(1) = 1
intArray(2) = 2
intArray(3) = 3
For intIndex = 1 To 3
Debug.Print intArray(intIndex);
Next
Debug.Print
' clear the array
ReDim intArray(3) As Integer
For intIndex = 1 To 3
Debug.Print intArray(intIndex);
Next
Debug.Print
End Sub
Bookmarks