In VBA I'm trying to generate an array (Array2) that takes values from another array (Array1) that meet a certain condition like the following code:
Should be simple enough... however something weird happens when I run the code. At the end of the code execution Array2 is the correct size but all items are blank/empty. And as I'm debugging my code I checked that after each iteration of for loop Array2 actually has the correct item value being assigned to the correct index, but somehow once the code exits the loop all entries become blank??
I spent way too long on trying to understand this at no avail, although it's probably something stupid. Hopefully someone can blow my mind
Code:
Dim j As Long
j = 0
For i = 0 To UBound(Array1)
If Left(Array1(i), 4) = cnstVal Then
ReDim Array2(j + 1)
Array2(j) = Array1(i)
j = j + 1
End If
Next i
End Sub
I spent way too long on trying to understand this at no avail, although it's probably something stupid. Hopefully someone can blow my mind