Ich habe mir einen Code zusammen gebastelt. Dieser funktioniert soweit auch. Klicke ich auf eine Zeile in ListBox1 (oben) dann verschiebt es mir diese in die ListBox2 (unten). Klicke ich auf die ListBox2 (unten), dann verschiebt es mir diese wieder in die ListBox1 (oben). Versuche ich dies ein zweites mal, so kann ich aus der ListBox2 die Zeile nicht wieder zurück in die ListBox1 verschieben. Was ist hier falsch?
Private Sub ListBox1_Click()
Static sblnRemoveItemEvent As Boolean
If Not sblnRemoveItemEvent Then
ListBox2.AddItem ListBox1.List(ListBox1.ListIndex, 0)
ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(ListBox1.ListIndex, 1)
ListBox2.List(ListBox2.ListCount - 1, 2) = ListBox1.List(ListBox1.ListIndex, 2)
ListBox2.List(ListBox2.ListCount - 1, 3) = ListBox1.List(ListBox1.ListIndex, 3)
ListBox2.List(ListBox2.ListCount - 1, 4) = ListBox1.List(ListBox1.ListIndex, 4)
ListBox2.List(ListBox2.ListCount - 1, 5) = ListBox1.List(ListBox1.ListIndex, 5)
sblnRemoveItemEvent = True
ListBox1.RemoveItem ListBox1.ListIndex
ListBox1.ListIndex = -1
Else
sblnRemoveItemEvent = False
End If
End Sub
Private Sub ListBox2_Click()
Static sblnRemoveItemEvent As Boolean
If Not sblnRemoveItemEvent Then
ListBox1.AddItem ListBox2.List(ListBox2.ListIndex, 0)
ListBox1.List(ListBox1.ListCount - 1, 1) = ListBox2.List(ListBox2.ListIndex, 1)
ListBox1.List(ListBox1.ListCount - 1, 2) = ListBox2.List(ListBox2.ListIndex, 2)
ListBox1.List(ListBox1.ListCount - 1, 3) = ListBox2.List(ListBox2.ListIndex, 3)
ListBox1.List(ListBox1.ListCount - 1, 4) = ListBox2.List(ListBox2.ListIndex, 4)
ListBox1.List(ListBox1.ListCount - 1, 5) = ListBox2.List(ListBox2.ListIndex, 5)
sblnRemoveItemEvent = True
ListBox2.RemoveItem ListBox2.ListIndex
ListBox2.ListIndex = -1
Else
sblnRemoveItemEvent = False
End If
End Sub
Private Sub UserForm_Initialize()
Dim lngZeile As Long
Dim lngZeileMax As Long
Dim lngSpalteMax As Long
Dim rngBereich As Range
Dim lngZ As Long
With Tabelle1
lngZeileMax = .Cells(.Rows.Count, 1).End(xlUp).Row
lngSpalteMax = .Cells(1, Columns.Count).End(xlToLeft).Column
Set rngBereich = .Range(.Cells(2, 1), .Cells(lngZeileMax, lngSpalteMax))
End With
With ListBox1
.List = rngBereich.Value
.ColumnCount = 6
.ColumnWidths = "170;170;130;130;90;30"
.ColumnHeads = True
.Font.Size = 12
End With
With ListBox2
.ColumnCount = 6
.ColumnWidths = "170;170;130;130;90;30"
.ColumnHeads = True
.Font.Size = 12
End With
End Sub
Besten Dank für Eure Hilfe.Gruss Daniel