Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

loop through listbox and delete items

excel vba
listbox on a userform:

When i load a listbox:
I need to delete all the items in the listbox that do not have the following codes in column 13
WG
WV
DG
DV
and also any nulls in column 13.


current code to delete items with a code of :
DG
DV
WG
WV


Dim i As Long
With Me.ListBox1
    For i =  .ListCount - 1 To 0 Step -1
        If .List(i, 13) = "DG" Or .List(i, 13) = "WD" Or .List(i, 13) = "DV" Or .List(i, 13) = "WV" Or .List(i, 13) = "WG" Then
            .RemoveItem i
        End If
    Next
End With


I think it would be this but need to delete nulls also:

Dim i As Long
With Me.ListBox1
    For i =  .ListCount - 1 To 0 Step -1
        If .List(i, 13) <> "DG" Or .List(i, 13) <> "WD" Or .List(i, 13) <> "DV" Or .List(i, 13) <> "WV" Or .List(i, 13) <> "WG" Then
            .RemoveItem i
        End If
    Next
End With

Thanks
fordraiders
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

tHANKS