inactiveUser214710
Board Regular
- Joined
- Apr 27, 2012
- Messages
- 171
Hi everyone
I would like to display in listbox(listbox 2) a row selection from another listbox(Listbox 1) with all its columns in userform. be will possible?
As one as the other, the codes below in listbox2 , gives me, one above the other, when I wish all the selection.
Which of these codes will be the most correct to be alterate?
Thank you
I would like to display in listbox(listbox 2) a row selection from another listbox(Listbox 1) with all its columns in userform. be will possible?
As one as the other, the codes below in listbox2 , gives me, one above the other, when I wish all the selection.
Which of these codes will be the most correct to be alterate?
Thank you
VBA Code:
Private Sub ListBox1_Click()
Me.ListBox2.AddItem ListBox1.Column(0, ListBox1.ListIndex)
Me.ListBox2.AddItem ListBox1.Column(1, ListBox1.ListIndex)
Me.ListBox2.AddItem ListBox1.Column(2, ListBox1.ListIndex)
Me.ListBox2.AddItem ListBox1.Column(3, ListBox1.ListIndex)
Me.ListBox2.AddItem ListBox1.Column(4, ListBox1.ListIndex)
Me.ListBox2.AddItem ListBox1.Column(5, ListBox1.ListIndex)
Me.ListBox2.AddItem ListBox1.Column(6, ListBox1.ListIndex)
OR
''other code that I take from net
Dim lastrow, curVal, x As Long
'find last row
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
' clear listbox2
Me.ListBox2.Clear
curVal = Me.ListBox1.Value
For x = 2 To lastrow
If Sheet1.Cells(x, "a") = curVal Then
'found a match; populate listbox2
Me.ListBox2.AddItem Sheet1.Cells(x, "a")
Me.ListBox2.AddItem Sheet1.Cells(x, "b")
Me.ListBox2.AddItem Sheet1.Cells(x, "c") '..........util all columns
End If
Next x
End Sub