I was wondering if anyone could help out here. Data is 20 columns (50k rows) with numbers and text (basically stock tickers with market values) and I am trying to use an array to speed up a loop. I already coded the For Next loop but was wondering if an array could improve the time to go through the data. Its seems easy and I thought it would work but I got a type mismatch error on this line
myArray2(a, 1) = myArray(i, 1)
meaning that something is wrong in the array setup. I see the array populated fine in the immediate window but I have no idea why this is happening. After the filtered new array is populated, I want to write it back to the worksheet and any help there would be appreciated.
Any help if greatly appreciated.
myArray2(a, 1) = myArray(i, 1)
meaning that something is wrong in the array setup. I see the array populated fine in the immediate window but I have no idea why this is happening. After the filtered new array is populated, I want to write it back to the worksheet and any help there would be appreciated.
Code:
Sub TestArry()
Dim ActiveSrc As Long
Dim myArray As Variant
Dim myArray2 As Variant
Dim i As Variant
Dim a As Variant
Dim ARow As Long
ARow = Worksheets("Misc").Rows(Rows.Count).End(xlUp).Row
myArray = Sheets("Misc").Range("A1:T" & ARow)
MsgBox "Array populated with " & UBound(myArray) & "entries."
a = 1
For i = 1 To UBound(myArray)
If myArray(i, 1) = "ABC" Or myArray(i, 4) = "XYZ" Then
myArray2(a, 1) = myArray(i, 1)
myArray2(a, 2) = myArray(i, 2)
myArray2(a, 3) = myArray(i, 3)
myArray2(a, 4) = myArray(i, 4)
myArray2(a, 5) = myArray(i, 5)
myArray2(a, 6) = myArray(i, 6)
myArray2(a, 7) = myArray(i, 7)
myArray2(a, 8) = myArray(i, 8)
myArray2(a, 9) = myArray(i, 9)
myArray2(a, 10) = myArray(i, 10)
myArray2(a, 11) = myArray(i, 11)
myArray2(a, 12) = myArray(i, 12)
myArray2(a, 13) = myArray(i, 13)
myArray2(a, 14) = myArray(i, 14)
myArray2(a, 15) = myArray(i, 15)
myArray2(a, 16) = myArray(i, 16)
myArray2(a, 17) = myArray(i, 17)
myArray2(a, 18) = myArray(i, 18)
myArray2(a, 19) = myArray(i, 19)
myArray2(a, 20) = myArray(i, 20)
a = a + 1
End If
Next i
MsgBox "Array populated now with " & UBound(myArray2) & "entries."
'How do I write back to sheet in Column AA????
End Sub
Any help if greatly appreciated.