I'm totally confused as to why an error would occur when it does in my code. The wierdest part is that it already run the code once during the loop.
Let me explain real quick what happens above this section of code. the code auto-creates a combobox and then fills it with data from Sheet4. Now in the code below I'm trying to delete any items in the box which are also listed in sheet2, thus making sure the user can't pick them.
Here's the code with the error line in bold:
The part which has me confused is that it always gets the error the second time through the loop right when it tries to increment to the last ListIndex. It doesn't matter what the last ListIndex is either. If I set the data in Sheet2 so that there are only 2 items (making the max ListIndex = 1) it stills stops before the last increment (ListIndex=0). If I set the data in sheet2 to 10 items, it stops before the last increment; this time the max ListIndex = 9 and it stops at 8.
The error I get is "Run-Time 440" "Automation Error".
Any thoughts?
Let me explain real quick what happens above this section of code. the code auto-creates a combobox and then fills it with data from Sheet4. Now in the code below I'm trying to delete any items in the box which are also listed in sheet2, thus making sure the user can't pick them.
Here's the code with the error line in bold:
Code:
compcount = 3
quickcount = 10
While Worksheets(2).Cells(compcount, TempCount + 1).Value <> ""
With cNewComboBox
cNewComboBox.ListIndex = 0
While cNewComboBox.ListIndex <> ""
On Error GoTo ErrorHandler
[b]cNewComboBox.ListIndex = cNewComboBox.ListIndex + 1[/b]
On Error Resume Next
Wend
ErrorHandler:
TempIndex = cNewComboBox.ListIndex
While TempIndex >= 0
If Worksheets(2).Cells(compcount, TempCount + 1).Value = cNewComboBox.Value Then
cNewComboBox.RemoveItem (TempIndex)
cNewComboBox.ListIndex = TempIndex
End If
TempIndex = TempIndex - 1
cNewComboBox.ListIndex = cNewComboBox.ListIndex - 1
Wend
End With
compcount = compcount + 1
Wend
The part which has me confused is that it always gets the error the second time through the loop right when it tries to increment to the last ListIndex. It doesn't matter what the last ListIndex is either. If I set the data in Sheet2 so that there are only 2 items (making the max ListIndex = 1) it stills stops before the last increment (ListIndex=0). If I set the data in sheet2 to 10 items, it stops before the last increment; this time the max ListIndex = 9 and it stops at 8.
The error I get is "Run-Time 440" "Automation Error".
Any thoughts?