Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
Anzeige
Archiv - Navigation
1832to1836
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Klick auf ListBox

Klick auf ListBox
21.05.2021 21:10:37
Daniel
Guten Abend
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

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Klick auf ListBox
21.05.2021 22:25:58
ralf_b

Private Sub ListBox1_change()
Dim indx As Integer
If ListBox1.ListIndex = -1 Then Exit Sub
indx = ListBox1.ListIndex
ListBox2.AddItem ListBox1.List(indx, 0)
ListBox2.List(ListBox2.ListCount - 1, 1) = ListBox1.List(indx, 1)
ListBox2.List(ListBox2.ListCount - 1, 2) = ListBox1.List(indx, 2)
ListBox2.List(ListBox2.ListCount - 1, 3) = ListBox1.List(indx, 3)
ListBox2.List(ListBox2.ListCount - 1, 4) = ListBox1.List(indx, 4)
ListBox2.List(ListBox2.ListCount - 1, 5) = ListBox1.List(indx, 5)
ListBox1.ListIndex = -1
ListBox1.RemoveItem indx
End Sub
Private Sub ListBox2_Change()
Dim indx As Integer
If ListBox2.ListIndex = -1 Then Exit Sub
indx = ListBox2.ListIndex
ListBox1.AddItem ListBox2.List(indx, 0)
ListBox1.List(ListBox1.ListCount - 1, 1) = ListBox2.List(indx, 1)
ListBox1.List(ListBox1.ListCount - 1, 2) = ListBox2.List(indx, 2)
ListBox1.List(ListBox1.ListCount - 1, 3) = ListBox2.List(indx, 3)
ListBox1.List(ListBox1.ListCount - 1, 4) = ListBox2.List(indx, 4)
ListBox1.List(ListBox1.ListCount - 1, 5) = ListBox2.List(indx, 5)
ListBox2.ListIndex = -1
ListBox2.RemoveItem indx
End Sub

Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige