Sub MakeNewArray()
Dim lngCounter As Long
Dim i As Long
lngCounter = 1
For i = LBound(sampleArr) To UBound(sampleArr)
If Len(CStr(sampleArr(i))) > 0 Then
myArr(lngCounter) = sampleArr(i)
lngCounter = lngCounter + 1
End If
Next i
End Sub
Dim myArr() As Variant, Item As Variant
Dim i As Integer
For Each Item In samplearr
If Len(Item) > 0 Then
i = i + 1
ReDim Preserve myArr(1 To i)
myArr(i) = Item
End If
Next Item
Hi, thans. How do I dimension the new array if I do not know how many indexes it needs in advance? It is telling me it isn't defined.
Sub MakeNewArray()
Dim lngCounter As Long
Dim i As Long
Dim myArr
Redim myArr(ubound(sampleArr))
lngCounter = 1
For i = LBound(sampleArr) To UBound(sampleArr)
If Len(CStr(sampleArr(i))) > 0 Then
myArr(lngCounter) = sampleArr(i)
lngCounter = lngCounter + 1
End If
Next i
then, Redim Preserve myArr(1 to lngCounter - 1)
I figured it out. My sampleArr() was 2D so I needed sampleArr(i,1)
Thanks for the code. Works perfect. @Dave, I didn't get a chance to try yours yet, but thanks for replying.