userform with 2 listboxes and 2 commandbuttons.
Private m_vntList As Variant
Private m_blnLstA() As Boolean
Private m_blnLstB() As Boolean
Private Sub CommandButton1_Click()
Dim lngIndex As Long
Dim lngItem As Long
lngIndex = 0
For lngItem = 0 To UBound(m_blnLstA)
If m_blnLstA(lngItem) Then
If ListBox1.Selected(lngIndex) Then
m_blnLstA(lngItem) = False
m_blnLstB(lngItem) = True
End If
lngIndex = lngIndex + 1
End If
Next
ListBox1.Clear
ListBox2.Clear
For lngItem = 0 To UBound(m_blnLstA)
If m_blnLstA(lngItem) Then
ListBox1.AddItem m_vntList(lngItem)
End If
If m_blnLstB(lngItem) Then
ListBox2.AddItem m_vntList(lngItem)
End If
Next
End Sub
Private Sub CommandButton2_Click()
Dim lngIndex As Long
Dim lngItem As Long
lngIndex = 0
For lngItem = 0 To UBound(m_blnLstA)
If m_blnLstB(lngItem) Then
If ListBox2.Selected(lngIndex) Then
m_blnLstB(lngItem) = False
m_blnLstA(lngItem) = True
End If
lngIndex = lngIndex + 1
End If
Next
ListBox1.Clear
ListBox2.Clear
For lngItem = 0 To UBound(m_blnLstA)
If m_blnLstA(lngItem) Then
ListBox1.AddItem m_vntList(lngItem)
End If
If m_blnLstB(lngItem) Then
ListBox2.AddItem m_vntList(lngItem)
End If
Next
End Sub
Private Sub UserForm_Initialize()
Dim lngIndex As Long
m_vntList = Array("A", "B", "C", "D", "E")
ListBox1.List = m_vntList
ReDim m_blnLstA(0 To ListBox1.ListCount - 1)
ReDim m_blnLstB(0 To ListBox1.ListCount - 1)
For lngIndex = 0 To ListBox1.ListCount - 1
m_blnLstA(lngIndex) = True
m_blnLstB(lngIndex) = False
Next
End Sub
Bookmarks