View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
gbpg gbpg is offline
external usenet poster
 
Posts: 58
Default command button that copies and pastes from one list box to ano

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

End Sub

this still does not work. I get an error compile errror

"JLatham" wrote:

You're basing i counter on ListBox2 list items, perhaps in the first If
ListBox3 doesn't have as many items in the list? Then you get an error
because you're trying to reference something that doesn't exist.

I think you probably meant:
For i = 0 to ListBox3.ListCount-1


"gbpg" wrote:

I inserted the below code to accomplish the below. Why do I get an error for
the i ?

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

End Sub