Data from Listbox1 to ListBox2

Status
Not open for further replies.

mrsec

Board Regular
Joined
Jan 28, 2016
Messages
54
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I have userform that has 2 listbox's,
Listbox1 shows the data from search and by Adding command button i can select single row and transfer/move it to Listbox2
But for some reason everytime i transfer a new row from LB1 to LB2 the first one that i transfer is been overwritten by the later.
My code
VBA Code:
Private Sub CommandButton2_Click()
    Dim i As Long
    ReDim b(1, 1 To 16)
With ListBox2
    .ColumnCount = 16
    .List = b
    .Clear
End With

    For i = Me.ListBox1.ListCount - 1 To 0 Step -1
        If Me.ListBox1.Selected(i) = True Then
            Me.ListBox2.AddItem Me.ListBox1.List(i)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 1) = Me.ListBox1.List(i, 1)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 2) = Me.ListBox1.List(i, 2)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 3) = Me.ListBox1.List(i, 3)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 4) = Me.ListBox1.List(i, 4)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 5) = Me.ListBox1.List(i, 5)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 6) = Me.ListBox1.List(i, 6)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 7) = Me.ListBox1.List(i, 7)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 8) = Me.ListBox1.List(i, 8)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 9) = Me.ListBox1.List(i, 9)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 10) = Me.ListBox1.List(i, 10)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 11) = Me.ListBox1.List(i, 11)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 12) = Me.ListBox1.List(i, 12)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 13) = Me.ListBox1.List(i, 13)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 14) = Me.ListBox1.List(i, 14)
            Me.ListBox2.List(Me.ListBox2.ListCount - 1, 15) = Me.ListBox1.List(i, 15)
            Me.ListBox1.RemoveItem i
     Exit For
        End If
    Next
End Sub
 

Attachments

  • listbox.jpg
    listbox.jpg
    100.6 KB · Views: 16
Is the problem fixed using dmt32 code in "the other" discussion?
Sort of,still doing some adjustment,the problem is when i select add from lb1 to lb2 the header goes with the data.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Is the problem fixed using dmt32 code in "the other" discussion?
after adjustment it kinda work,the issue now is after i transfer a new data from Worksheet to LB1 the option to add it in to LB2 greyed out.Unlike if I have multiple/continous row it works.
 

Attachments

  • gryedout.PNG
    gryedout.PNG
    41.7 KB · Views: 6
  • notgrey.JPG
    notgrey.JPG
    118 KB · Views: 7
Upvote 0
Is the problem fixed using dmt32 code in "the other" discussion?
after few adjustments,the problem is if i transfer every row from LB1 to LB2 then the transfer function stop.but if i transfer just a few rows from the selection i can continously transfer data.
 

Attachments

  • greyedpartwo.JPG
    greyedpartwo.JPG
    81.5 KB · Views: 6
Upvote 0
Duplicate to: Tow listbox in One Userform

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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