Skip to main content

Remove Blanks from an Array

This function will remove any blank elements within an array.

Snippet

Private Function removeBlanksFromArray()
   Dim tempArray() As String
   Dim i, ILoop As Integer
   ReDim tempArray(0)

   For ILoop = 0 To UBound(listbox1$)
      If listbox1$(ILoop) <> "" Then
         tempArray(UBound(tempArray)) = listbox1$(ILoop)
         ReDim preserve tempArray(UBound(tempArray) + 1)
       End If
   Next ILoop
   i = UBound(tempArray)
   Erase listbox1$
   ReDim listbox1$(i)
   For ILoop = 0 To UBound(tempArray)
      listbox1$(ILoop) = tempArray(ILoop)
   Next ILoop

End Function