Toggle Listbox in VBA

Joined
Mar 20, 2012
Messages
2
Reaction score
0
Hi All,

I am trying to create a toggle list box through VBA.

On my form i am having two listboxes and two buttons.

I am having a defined range of elements in Listbox1. Now i am trying to move the selected element to the next Listbox2 (Which i am able to do) and along with this i need to perform 2 functions:
1.The value which is selected from Listbox1 should be deleted and added to listbox2.
2.On adding the value to listbox2 we need to update it on excel sheet also.

Could someone please help into this.

Thanks & Regards,
Preetpal:D
 
Joined
Mar 20, 2012
Messages
2
Reaction score
0
My Code is :
Private Sub CommandButton1_Click()


Call move_Right
End Sub


Sub move_Right()
Dim i As Integer

If ListBox1.ListIndex = -1 Then Exit Sub

For i = ListBox1.ListCount - 1 To 0 Step -1

If ListBox1.Selected(i) = True Then

ListBox2.AddItem ListBox1.List(i)

ListBox1.RemoveItem i

End If

Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top