Overseer10
Overseer10

Reputation: 361

Excel VBA Drag and Drop

I'm having some difficulty finding a workable solution (been looking for 2 days now). Hopefully you can help me figure it out.

Purpose - I'm trying to use VBA to drag and drop text between listboxes (see image)

enter image description here

Note: I know there are Pivot Wizards already, I'm not so interested in them (long story)

Question Is there any solution that you know of that could help me move "Column A" to any of the other listbox?

If you don't know of a solution, a blog or site might be helpful as well.

Upvotes: 1

Views: 9955

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149295

Further to my comments above here is the most simple way to do it.

Create a Userform with 2 Listboxes and 1 Command Button as shown in the below image.

enter image description here

And paste this code in the Userform Code area

Dim i As Long

Private Sub UserForm_Initialize()
    For i = 1 To 10
        ListBox1.AddItem i
    Next i
End Sub

Private Sub CommandButton1_Click()
    If ListBox1.ListIndex = -1 Then
        MsgBox "Please select an item from listbox1"
        Exit Sub
    End If

    ListBox2.AddItem ListBox1.List(ListBox1.ListIndex)
    ListBox1.RemoveItem (ListBox1.ListIndex)
End Sub

HTH

Upvotes: 2

Related Questions