我正在尝试删除用户表单列表框中的所有项目,但特定值除外
可以说我要删除列表框中除“猫”和“狗”之外的所有内容
我写:
For i = 0 To ListBox2.ListCount - 1
If ListBox2.List(i) <> "Cat" or ListBox2.List(i) <> "Dog" Then
ListBox2.RemoveItem i
End If
Next
由于某种原因它不起作用,我试图找到一种解决方案,但我没有。这是怎么了
使用向后循环:
For i = ListBox2.ListCount - 1 To 0 Step -1
If ListBox2.List(i) <> "Cat" AND ListBox2.List(i) <> "Dog" Then
ListBox2.RemoveItem i
End If
Next
并在您的陈述中更改OR
为AND
IF
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句