C
Chip Pearson
When you remove items from a ListBox or a ComboBox (or, also, Rows from a
Range), you should work your way from the bottom up, not top down. That is,
your loop should go from ListCount-1 to 0, not from 0 to ListCount-1.
Otherwise, your index will get screwed up as you delete an item. For
example, if you select Item(5) and delete it, what was originally Item(6) is
now Item(5). If you then delete Item(6), you are deleting what was
originally Item(7). All this can be avoided by starting with ListCount-1 and
moving down to 0. E.g.,
Dim N As Long
For N = .ListCount-1 To 0 Step -1
If Something(N) = True Then
.RemoveItem N
End If
Next N
--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
Range), you should work your way from the bottom up, not top down. That is,
your loop should go from ListCount-1 to 0, not from 0 to ListCount-1.
Otherwise, your index will get screwed up as you delete an item. For
example, if you select Item(5) and delete it, what was originally Item(6) is
now Item(5). If you then delete Item(6), you are deleting what was
originally Item(7). All this can be avoided by starting with ListCount-1 and
moving down to 0. E.g.,
Dim N As Long
For N = .ListCount-1 To 0 Step -1
If Something(N) = True Then
.RemoveItem N
End If
Next N
--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)