AW: ListBox füllen
23.05.2021 10:07:03
Beverly
Hi Daniel,
du kannst die 3 ListBoxen in 1 Schleife füllen:
Private Sub UserForm_Initialize()
Dim rngBereich As Range
Dim rngLetzte As Long
Dim LetzteLager As Long
Dim ws As Worksheet
Set ws = Worksheets(1)
rngLetzte = ws.Cells(Rows.Count, 1).End(xlUp).Row
With ListBox1
.Clear
.ColumnCount = 5
.ColumnWidths = "180;180;100;10;0" 'Breite der Spalte
.Font.Size = 12
End With
With ListBox2
.Clear
.ColumnCount = 5
.ColumnWidths = "180;180;100;10;0" 'Breite der Spalte
.Font.Size = 12
End With
With ListBox3
.Clear
.ColumnCount = 5
.ColumnWidths = "180;180;100;10;0" 'Breite der Spalte
.Font.Size = 12
End With
For Each rngBereich In ws.Range("A2:A" & rngLetzte)
If rngBereich "" Then
If rngBereich.Font.ColorIndex = 1 Then
ListBox1.AddItem rngBereich.Text
ListBox1.List(ListBox1.ListCount - 1, 1) = rngBereich.Offset(, 1).Text
ListBox1.List(ListBox1.ListCount - 1, 2) = rngBereich.Offset(, 2).Text
ListBox1.List(ListBox1.ListCount - 1, 3) = rngBereich.Offset(, 3).Text
ListBox1.List(ListBox1.ListCount - 1, 4) = rngBereich.Address
End If
If rngBereich.Offset(, 5) = "Dabei" Or rngBereich.Offset(, 5) = "" Then
ListBox2.AddItem rngBereich.Text
ListBox2.List(ListBox2.ListCount - 1, 1) = rngBereich.Offset(, 1).Text
ListBox2.List(ListBox2.ListCount - 1, 2) = rngBereich.Offset(, 2).Text
ListBox2.List(ListBox2.ListCount - 1, 3) = rngBereich.Offset(, 3).Text
ListBox2.List(ListBox2.ListCount - 1, 4) = rngBereich.Address
End If
If rngBereich.Font.ColorIndex = 3 Then
ListBox3.AddItem rngBereich.Text
ListBox3.List(ListBox3.ListCount - 1, 1) = rngBereich.Offset(, 1).Text
ListBox3.List(ListBox3.ListCount - 1, 2) = rngBereich.Offset(, 2).Text
ListBox3.List(ListBox3.ListCount - 1, 3) = rngBereich.Offset(, 3).Text
ListBox3.List(ListBox3.ListCount - 1, 4) = rngBereich.Address
End If
End If
Next rngBereich
End Sub