listbox remove item according to the value

B

baha17

hi All,
I have a list box which displays the sheet names from 201 to 843(these
are the names of the worksheets).What I need,when I click on command
button if the checkbox1 is check then remove all the item less then
800 from the list. So far I made the below code but I only removes one
item less than 800.How can I remove all the items less than 800É
If CheckBox1.Value = True Then
Dim i As Long
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.List(i) < 800 Then
Me.ListBox1.RemoveItem (i)
Exit Sub
End If
Next i
End If
Thanks for help and happy new year.
 
B

Bob Phillips

If CheckBox1.Value = True Then
Dim i As Long
For i = Me.ListBox1.ListCount - 1 To 0 Step -1
If Me.ListBox1.List(i) < 800 Then
Me.ListBox1.RemoveItem (i)
End If
Next i
End If



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

hi All,
I have a list box which displays the sheet names from 201 to 843(these
are the names of the worksheets).What I need,when I click on command
button if the checkbox1 is check then remove all the item less then
800 from the list. So far I made the below code but I only removes one
item less than 800.How can I remove all the items less than 800É
If CheckBox1.Value = True Then
Dim i As Long
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.List(i) < 800 Then
Me.ListBox1.RemoveItem (i)
Exit Sub
End If
Next i
End If
Thanks for help and happy new year.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top