View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
asmenut asmenut is offline
external usenet poster
 
Posts: 59
Default Listbox counter help

I have two list boxes, (1) that initally holds the data and (1) that can be
added to:
I first fill the List_AddFrom box with items, then check to see if a certain
checkbox is true. If the Checkbox is true, it adds another item ("1st Piece
Sample") into the List_AddFrom Box.

Then I read in items from a sheet into the List_AddTo box. I then compare
the two boxes and remove any duplication from the List_AddFrom box. This
works great unless the the List_AddTo box reads in the "1st Piece Sample"
from the sheet.

Once it compares and removes the "1st Piece Sample" item from the
List_AddFrom box, the next loop gives a List Property array index error (it
comes from the LIst_AddFrom box). This happens regardless of where the "1st
Piece Sample" is located in the box (first, last, middle).

I have rewritten the counters several times (0 to .listcount -1, 0 to
..listcount, .Listcount to 0 step -1) and have even created internal counters
(i = i-1, j = j-1, etc), to counter the error, but to no avail. How can I
fix this? (Code below)

Private Sub Load_NLBoxes()
Dim i As Integer
Dim j As Integer

'Load the List_AddFrom listbox with data
If LAFStr = "" Then
With List_AddFrom
.RowSource = ""
.Clear
.AddItem "Rescinds PEC"
.AddItem "Preventive Action"
.AddItem "UL/CSA/CE Affected"
.AddItem "Manual Change Required"
.AddItem "S/N at Changeover"
.AddItem "Cost Increase over 5%"
End With
CheckSample
Else
Exit Sub
End If

'Validate List_AddFrom Listbox with List_AddTo listbox and remove items as
necessary
' If List_AddFrom.ListIndex = -1 Then Exit Sub
For i = 0 To List_AddFrom.ListCount - 1
For j = 0 To List_AddTo.ListCount - 1
If List_AddTo.List(j) = List_AddFrom.List(i) Then
List_AddFrom.RemoveItem (i)
i = i + 1
End If
Next j
Next i
End Sub