Was wirklich schwieriges !!!
23.02.2009 14:40:42
A.Franz
ich hoffe mir kann jemand helfen.Ich habe eine ListBox mit 10-Spalten die ihre Werte aus Tabelle 1 bezieht.Weiterhin habe ich eine TextBox in der ich einen Suchbegriff eingebe, damit mir dann nur noch alle Werte in der ListBox angezeigt werden die mit dem Suchbegriff übereinstimmen.Funktioniert auch schon teilweise, aber nun mein Problem.Die ListBox enthällt viele doppelte Werte.Z.B in Spalte 2 stehen Namen.Wenn ich nun über die TextBox z.B den Namen "Müller" suchen lasse, der bestimmt 5 mal in meiner Tabelle vorkommt, zeigt mir die ListBox immer nur die erste Zeile an, in der der Name Müller vorkommt.Ich hätte aber gerne das mir dann alle Zeilen die den Name Müller haben angezeigt werden.Komisch, wenn die Einträge mit Müller in der Tabelle direkt untereinander stehen funktionierts.Sobald aber dazwischen andere Namen vorkommen, wird immer nur der erste gefundene Eintrag angezeigt.
Kann mir hier bitte jemand weiterhelfen...?
Ich habe alles mögliche probiert, ich kriege es nicht hin!
Hier meine verwendeten Codes,
So wird die ListBox befüllt:
Private Sub UserForm_Activate() With Worksheets("Tabelle1") LoLetzte = IIf(IsEmpty(.Cells(.Rows.Count, 1)), .Cells(.Rows.Count, 1).End(xlUp).Row, .Rows. _ Count) ListBox1.RowSource = "A2:J" & LoLetzte ListBox1.ColumnCount = 10 End With End Sub
So wird mit dem Suchbegriff gesucht:
Private Sub CommandButton3_Click()
Dim LoI As Long
Dim LoZeile As Long
Dim RaFound As Range
Application.ScreenUpdating = False
If TextBox1 = "" Then
ListBox1.RowSource = "A2:J" & LoLetzte
Else
ListBox1.RowSource = ""
With Worksheets("Tabelle1")
Set RaFound = .Columns(1).Find(TextBox1 & "*", .Range("A1"), , xlWhole, , xlNext)
If Not RaFound Is Nothing Then
For LoI = RaFound.Row To LoLetzte
If UCase(Left(.Cells(LoI, 1), Len(TextBox1))) = UCase(TextBox1) Then
ListBox1.AddItem .Cells(LoI, 1).Text
ListBox1.List(LoZeile, 1) = .Cells(LoI, 2).Text
ListBox1.List(LoZeile, 2) = .Cells(LoI, 3).Text
ListBox1.List(LoZeile, 3) = .Cells(LoI, 4).Text
ListBox1.List(LoZeile, 4) = .Cells(LoI, 5).Text
ListBox1.List(LoZeile, 5) = .Cells(LoI, 6).Text
ListBox1.List(LoZeile, 6) = .Cells(LoI, 7).Text
ListBox1.List(LoZeile, 7) = .Cells(LoI, 8).Text
ListBox1.List(LoZeile, 8) = .Cells(LoI, 9).Text
ListBox1.List(LoZeile, 9) = .Cells(LoI, 10).Text
LoZeile = LoZeile + 1
Else
Exit For
End If
Next
End If
End With
End If
Set RaFound = Nothing
Application.ScreenUpdating = True
End Sub
Gruß Andre