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

stirlingmw

Board Regular
Joined
Feb 18, 2013
Messages
75
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

Code:
[COLOR=#000000][FONT=Courier][FONT=Verdana, Geneva, sans-serif]listdest.additem listdest.list(listdest.listcount -1,1)=listsource.list(listsource.listcount-1,1).value[/FONT]
[/FONT][/COLOR]
[COLOR=#000000][FONT=Courier][FONT=Verdana, Geneva, sans-serif]listdest.additem listdest.list(listdest.listcount -1,2)=listsource.list(listsource.listcount-1,2).value[/FONT]
[/FONT][/COLOR]
[FONT=&quot]
[/FONT]

Where am I going wrong?

Thanks

Steve
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try this

Code:
Private Sub CommandButton1_Click()
    For i = 0 To listsource.ListCount - 1
        filled = False
        For j = 0 To listsource.ColumnCount - 1
            If listsource.List(i, j) <> "" Then
                filled = True
                Exit For
            End If
        Next
        If filled Then
            [COLOR=#0000ff]listdest.AddItem[/COLOR] listsource.List(i, 0)
            listdest.List(listdest.ListCount - 1, 1) = listsource.List(i, 1)
            listdest.List(listdest.ListCount - 1, 2) = listsource.List(i, 2)
            listdest.List(listdest.ListCount - 1, 3) = listsource.List(i, 3)
        End If
    Next
End Sub
 
Upvote 0
Dante

Thank you again. works perfectly. I did however have to change the numbers at the end of the code from 1 to 0 and 2 to 1.

Code:
Edit.ListDESLead.List(Edit.ListDESLead.ListCount - 1, 0) = Me.ListBox2.List(i,[COLOR=#ff0000] 0[/COLOR])
Edit.ListDESLead.List(Edit.ListDESLead.ListCount - 1, 1) = Me.ListBox2.List(i, [COLOR=#ff0000]1[/COLOR])
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top