This gives that error:
VB Code:
Dim lngIdxAll As Long
Dim strAll() As String
ReDim strAll(1 To 9)
strAll(5) = "302"
For lngIdxAll = 1 To UBound(strAll)
If Val(strAll(lngIdxAll)) = 302 Then
ReDim Preserve strAll(lngIdxAll - 1) 'remove lines starting at START 302
Exit For
End If
Next lngIdxAll
This does not give that error (see difference in line #4):
VB Code:
Dim lngIdxAll As Long
Dim strAll() As String
ReDim strAll(0 To 9)
strAll(5) = "302"
For lngIdxAll = 1 To UBound(strAll)
If Val(strAll(lngIdxAll)) = 302 Then
ReDim Preserve strAll(lngIdxAll - 1) 'remove lines starting at START 302
Exit For
End If
Next lngIdxAll
Either make sure that strAll is initially zero-based, or include the lower bound when you redim the array. ReDim Preserve strAll(1 To lngIdxAll - 1)