excel - Removing items from listbox according to their values VBA -


I am trying to delete all items in a user form list-box except for specific values ​​ < P> says that I want to delete everything in my list box except "Cat" and "dog"

I have written:

  I = 0 ListBox2.ListCount - 1 for ListBox2.List (i) & lt; & Gt; "Cat" or Listbox 2. List (i) & lt; & Gt; "Dog" then ListBox2.RemoveItem i End if next   

For some reason this does not work, I tried to find a solution but I could not. What's wrong here?

Use the back loop:

  i ListBox2. ListCount- 1 to 0 Step-1 If ListBox2.List (i) & lt; & Gt; "Cat" and List Box 2. List (i) & lt; & Gt; "Dog" then listbox2.RemoveItem i End if Next   

and OR to and on your if Statement

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -