Copy the contents of a multicolumn listbox to another multicolumn on another Userfrom RRS feed

  • Question

  • I am trying to pass a Listbox multicolumn selection over to another multicolumn Listbox on another open Userform, but only if there is text on at least one of the source listbox columns/

    I have tried

    listdest.additem listdest.list(listdest.listcount -1,1)=listsource.list(listsource.listcount-1,1).value
    listdest.additem listdest.list(listdest.listcount -1,2)=listsource.list(listsource.listcount-1,2).value

    Where am I going wrong?



    Thursday, May 30, 2019 7:03 PM


  •  I can't make out what you're trying to do with that code but to copy a row from a listbox in one userform to a listbox in another try something like this...

    Dim frm As UserForm  ' As Object might be more useful
    Dim lbFrm1 As MSForms.ListBox
    Dim lbFrm2 As MSForms.ListBox
        Set lbFrm1 = Me.ListBox1
        If lbFrm1.ListIndex >= 0 Then
            For Each frm In UserForms
                If frm Is UserForm2 Then
                    Set lbFrm2 = frm.ListBox1
                    For c = 0 To 1
                        lbFrm2.List(lbFrm2.ListCount - 1, c) = lbFrm1.List(lbFrm1.ListIndex, c)
                End If
        End If
    Various ways of establishing a reference to the other form

    • Marked as answer by Stirlingmw Monday, June 3, 2019 2:49 PM
    Friday, May 31, 2019 6:58 PM