View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
ExcelMonkey[_190_] ExcelMonkey[_190_] is offline
external usenet poster
 
Posts: 172
Default Userform with Multiple ListBoxes not working

Its funny because I copies this from an old macro I had
without much thought as to how it worked. It was working
fine at first and then it stopped. I just did a search in
my code on cbDuplicates and it only comes up with 1
occurence - the one in the code snippet I posted. What
role is that playing in that specific line of code? I
can't seem to figure out why its there and what it is
doing?


-----Original Message-----
I can't get the error myself, it works fine.

Maybe cbDuplicates is some Boolean variable set when the

listbox item is
selected?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"ExcelMonkey" wrote

in message
...
I have a userform which has two listboxes. Listbox1

lists
all these sheets in my spreadsheet. there is an Add and
Delete button which allows teh user to click on items in
Listbox1 and add them to Listbox2. When I click onto 1
item in Listbox1 and then press Add, the code fails. I
can't figure out why this is failing. It was working
before. I am getting a:

Run Time Error
Type mismatch error

The last line of code that says:

ListBox2.AddItem ListBox1.Value

Has a null value for ListBox1.Value. This usually has

the
name of the sheet I have selected. Another thing is

that
I cannot remember what cbDuplicates is. Its not a
variable name.

Private Sub AddButton_Click()
If ListBox1.ListIndex = -1 Then Exit Sub
If Not cbDuplicates Then
' See if item already exists
For i = 0 To ListBox2.ListCount - 1
If ListBox1.Value = ListBox2.List(i) Then
Beep
Exit Sub
End If
Next i
End If
ListBox2.AddItem ListBox1.Value
End Sub




.