I've been struggling for a while now with passing a listbox to a sub. After 3 days of searching... i need help. My ultimate goal is to select item in one listbox then click button and have it move to another listbox. Here's what I've tried so far.
In UserForm:
Private Sub CommandButton7_Click()
Dim lbINDX As Integer
Dim lbSource As String, lbDest As String
lbINDX = ListBox3.ListIndex
lbSource = Me.ListBox3.Name
lbDest = Me.ListBox1.Name
Call move(lbINDX, lbSource, lbDest)
End Sub
In Userform sub I've also tried: (without .name) lbSource & lbDest as object, control, listbox, and msforms.listbox
In Module:
Private Sub move(itm As Integer, objTarget As String, objDest As String)
txt = objTarget.ListIndex(itm).Text
UserForm10.Controls(objTarget).RemoveItem Item:=itm
UserForm10.Controls(objDest).AddItem txt
End Sub
In Module sub I've also tried: (with and without Userform10.Controls()) objTarget & objDest as object, control, listbox, and msforms.listbox
How do I pass the listbox as a whole through a variable? Or is there an easier way?
Revision 1 in response to Nathan_Sav:
Private Sub CommandButton7_Click()
Dim lbINDX As Long
Dim lbSource As MSForms.ListBox, lbDest As MSForms.ListBox
lbINDX = ListBox3.ListIndex
Set lbSource = Me.ListBox3
Set lbDest = Me.ListBox1
Call move(lbINDX, lbSource, lbDest)
End Sub
and
Private Sub move(lngIndex As Long, objSource As MSForms.ListBox, objDest As MSForms.ListBox)
objDest.AddItem objSource.ListIndex(lngIndex).Text
objSource.RemoveItem Item:=lngIndex
End Sub