1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Option Explicit
Dim rng As Range, sht As Worksheet
Private Sub UserForm_Initialize()
InitData
InitListBox
End Sub
Private Sub InitData()
Set sht = ThisWorkbook.Worksheets("db")
Set rng = sht.Range("A1").CurrentRegion
End Sub
Private Sub InitListBox()
Dim r As Long, c As Integer, ColWidth As String
ColWidth = "0;50;50;50"
With ListBox1
.ColumnCount = rng.Columns.Count
.ColumnWidths = ColWidth
For r = 2 To rng.Rows.Count ' Maximum 9
'If rng.Cells(r, 5) = "F" And rng.Cells(r, 6) = "C" Then
.AddItem r
For c = 1 To rng.Columns.Count: .List(.ListCount - 1, c) = sht.Cells(r, c): Next
'End If
Next r
End With
With ListBox2
.ColumnCount = rng.Columns.Count
.ColumnWidths = ColWidth
End With
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
MoveListBox Me.ListBox1, Me.ListBox2
End Sub
Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
MoveListBox Me.ListBox2, Me.ListBox1
End Sub
Sub MoveListBox(FromListBox As MSForms.ListBox, ToListBox As MSForms.ListBox)
Dim c As Integer
With FromListBox
ToListBox.AddItem .List(.ListIndex, 0)
For c = 1 To .ColumnCount: ToListBox.List(ToListBox.ListCount - 1, c) = .List(.ListIndex, c): Next
.RemoveItem (.ListIndex)
End With
End Sub |
Partager