|
-
May 28th, 2008, 11:52 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] listbox add items
I have listbox2 and listbox 3. All this is the multiselect.
After select the items in the listbox2, It will added the items into listbox3. So How I can remove the items selected in the listbox2 after added the items in the listbox3?
Code:
For i = 0 To List2.ListCount - 1 'select sheet
If List2.Selected(i) = True Then
List3.AddItem (List2.List(i))
End If
Next
-
May 28th, 2008, 11:56 AM
#2
Re: listbox add items
Code:
Private Sub Command1_Click()
Dim i As Long
For i = List2.ListCount - 1 To 0 Step -1 ' counts list entries
If List2.Selected(i) = True Then ' if selected then
List3.AddItem List2.List(i) ' add to other list
List2.RemoveItem i ' optional remove
End If
Next
End Sub
-
May 28th, 2008, 12:03 PM
#3
Thread Starter
Frenzied Member
Re: listbox add items
Thank you. Hack.
I try to pop up the messagebox if not items is selected in the list2, but it not pop up the messagebox. Why?
If List2.ListIndex = -1 Then
MsgBox "Please choose items in the list2"
Exit Sub
End If
-
May 28th, 2008, 12:09 PM
#4
Re: listbox add items
You need to loop through the listbox but as soon as you find one thing selected, you can get out.
Code:
Dim blnHasSelected As Boolean
Dim i As Long
For i = 0 To List.ListCount - 1
If List1.Selected(i) = True Then
blnHasSelected = True
Exit For
End If
Next
If blnHasSelected = False Then
MsgBox "You have not selected anything.", vbOKOnly + vbInformation, "Select Something"
End If
-
May 28th, 2008, 12:26 PM
#5
Thread Starter
Frenzied Member
Re: listbox add items
Thank you so much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|