Ich habe eine Excel Datenbank die ich mittels VBA Form fülle und pflege.
Nun habe ich ein Textfeld (suchenTextFeld) und Commandbutton (suchenButton)
um die Listbox mit vorhandenen Einträge zu durchsuchen.
Ich möchte im Textfeld ein Wort oder Buchstaben eingeben
und durch klick auf den Commandbutton soll dann die ganze Datenbank Liste
durchsucht und alle Treffer in der Listbox anzeigt werden.
Die suche Funktioniert bereits, jedoch wird mir immer nur ein Treffer
in der Liste angezeigt. Zudem wird nur die erste Spalte durchsucht (Spalte A).
Es sollte jedoch die ganze Liste durchsucht werden.
Das ist mein Code soweit:
Private Sub suchenButton_Click()
Dim LoI As Long
Dim LoZeile As Long
Dim RaFound As Range
Application.ScreenUpdating = False
If suchenTextBox = "" Then
ListBox1.RowSource = "A2:I" & LoLetzte
Else
ListBox1.RowSource = ""
With Worksheets("Datenbank")
Set RaFound = .Columns(1).Find(suchenTextBox & "*", .Range("A1"), , xlWhole, , xlNext)
If Not RaFound Is Nothing Then
For LoI = RaFound.Row To .Columns(1).Find(suchenTextBox & "*", .Range("A65536")
, , xlWhole, , _
_
_
xlprevioius).Row
If UCase(Left(.Cells(LoI, 1), Len(suchenTextBox))) = UCase(suchenTextBox) 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
End If
Next
End If
End With
End If
Set RaFound = Nothing
Application.ScreenUpdating = True
End Sub
Von Michael kam dazu folgender Code:
Private Sub suchenButton_Click()
Dim LoI As Long
Dim LoZeile As Long
Dim temp As Long
Dim RaFound As Range
Application.ScreenUpdating = False
LoZeile = Worksheets("Datenbank").Cells(Worksheets("Datenbank").Rows.Count, 1).End(xlUp).Row
If suchenTextBox = "" Then
listbox1.RowSource = "A2:I" & LoZeile
Else
listbox1.RowSource = ""
With Worksheets("Datenbank")
For zeile = 2 To LoZeile
Set RaFound = .Rows(LoZeile).Find(suchenTextBox & "*", , , xlPart, , xlNext)
If Not RaFound Is Nothing Then
listbox1.AddItem .Cells(LoI, 1).Text
temp = listbox1.ListCount - 1
listbox1.List(temp, 1) = .Cells(zeile, 2).Text
listbox1.List(temp, 2) = .Cells(zeile, 3).Text
listbox1.List(temp, 3) = .Cells(zeile, 4).Text
listbox1.List(temp, 4) = .Cells(zeile, 5).Text
listbox1.List(temp, 5) = .Cells(zeile, 6).Text
listbox1.List(temp, 6) = .Cells(zeile, 7).Text
listbox1.List(temp, 7) = .Cells(zeile, 8).Text
listbox1.List(temp, 8) = .Cells(zeile, 9).Text
listbox1.List(temp, 9) = .Cells(zeile, 10).Text
End If
Next
End With
End If
Set RaFound = Nothing
Application.ScreenUpdating = True
End Sub
Leider hat dieser ebenfalls nicht funktioniert.
Ich danke bereits jetzt für eure Hilfe!!!
Liebe Grüsse
Marina