A
Ayo
I have 2 listboxes on a userform, When I select items from one to the other
and back, the items are always showing at the bottom of the list. Is there a
way to make the sort ascending, everytime a nd item is returned to its
original listbox?
So far, I use 2 commandbuttons cmdSelect and cmdDeselect to move items
between the two listboxes. The click event codes for these buttons follows:
Private Sub cmdSelect_Click()
Dim Msg, Style, Title
Me.ListBox2.Enabled = True
For i = 0 To ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) = True And i <= 25 Then
Me.ListBox2.AddItem ListBox1.List(i)
ElseIf ListBox1.Selected(i) = True And i > 25 Then
Msg = "25 sites maximum is allowed" ' Define message.
Style = vbOKOnly + vbInformation + vbDefaultButton1 ' Define
buttons.
Title = "Maximum Selections Allowed" ' Define title.
Exit For
End If
Next i
For i = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(i) = True Then
ListBox1.RemoveItem i
End If
Next i
End Sub
Private Sub cmdDeselect_Click()
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ListBox1.AddItem ListBox2.List(i)
End If
Next i
For i = ListBox2.ListCount - 1 To 0 Step -1
If ListBox2.Selected(i) = True Then
ListBox2.RemoveItem i
End If
Next i
If ListBox2.ListCount = 0 Then
Me.cmdDeselect.Enabled = False
Me.cmdDeselectAll.Enabled = False
End If
End Sub
and back, the items are always showing at the bottom of the list. Is there a
way to make the sort ascending, everytime a nd item is returned to its
original listbox?
So far, I use 2 commandbuttons cmdSelect and cmdDeselect to move items
between the two listboxes. The click event codes for these buttons follows:
Private Sub cmdSelect_Click()
Dim Msg, Style, Title
Me.ListBox2.Enabled = True
For i = 0 To ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) = True And i <= 25 Then
Me.ListBox2.AddItem ListBox1.List(i)
ElseIf ListBox1.Selected(i) = True And i > 25 Then
Msg = "25 sites maximum is allowed" ' Define message.
Style = vbOKOnly + vbInformation + vbDefaultButton1 ' Define
buttons.
Title = "Maximum Selections Allowed" ' Define title.
Exit For
End If
Next i
For i = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(i) = True Then
ListBox1.RemoveItem i
End If
Next i
End Sub
Private Sub cmdDeselect_Click()
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
ListBox1.AddItem ListBox2.List(i)
End If
Next i
For i = ListBox2.ListCount - 1 To 0 Step -1
If ListBox2.Selected(i) = True Then
ListBox2.RemoveItem i
End If
Next i
If ListBox2.ListCount = 0 Then
Me.cmdDeselect.Enabled = False
Me.cmdDeselectAll.Enabled = False
End If
End Sub