
Originally Posted by
Merri
Spoo, you can still keep the logic simple, you just need to reconsider the order you do things:
Code:
kk = 0
kill = "B"
For ii = 0 to UBound(MyArray)
If MyArray(ii) <> kill Then
If kk < ii Then
MyArray(kk) = MyArray(ii)
MyArray(ii) = Empty
End If
kk = kk + 1
Else
MyArray(ii) = Empty
End If
Next ii
That's the code I was looking for in the OP. I don't see a need to zero out deleted values, though, since they'll either get overwritten or redimmed into the void.
Code:
Private Sub FilterUDT(ptyp() As TESTUDT, pstrFilter As String)
Dim lngKeep As Long
Dim lngSwap As Long
For lngSwap = 0 To UBound(ptyp)
If ptyp(lngSwap).B <> pstrFilter Then
If lngKeep < lngSwap Then ptyp(lngKeep) = ptyp(lngSwap)
lngKeep = lngKeep + 1
End If
Next
Select Case lngKeep
Case 0: Erase ptyp
Case Is <= UBound(ptyp): ReDim Preserve ptyp(lngKeep - 1)
End Select
End Sub