Bei Volltextsuche Datensatz nur EINMAL ausgeben
31.07.2003 13:17:55
Bravestar
bei meiner Volltextsuche funktioniert alles wunderbar. Es wird alles gefunden und auch ausgegeben. Da pro Zeile der Suchbegriff in mehreren Spalten des Datenblattes vorkommen kann, möchte ich gerne verhindern, dass diese Zeile dann mehrmals in die Ergebnisliste übertragen wird. Das Grundprinzip der Suche stammt von einem Mitglied hier Namens Ivan.
Dabei bräuchte ich nun Hilfe. Hier mal der Code:
Private Sub CmdAbbruch_Click()
Unload Me
End Sub
Private Sub CommandButton1_Click()
'Suchfunktion, die die Ergebnisse in eine Listbox schreibt
Dim s As String
Dim Found As Range
Dim FirstAddress As String
Dim i As Integer ' Zeile
i = 0
If txtSuche.Text = "" Then
MsgBox "Suchbegriff fehlt!", vbCritical, "Was soll ich den suchen?"
txtSuche.SetFocus
Else
End If
Eingabe = txtSuche.Text
If Eingabe = "" Then Exit Sub
ListBox1.Clear
ListBox2.Clear
With ActiveSheet
Set Found = .Cells.Find(Eingabe, LookAt:=xlPart)
If Not Found Is Nothing Then
FirstAddress = Found.Address
ListBox1.ColumnCount = 2
ListBox1.AddItem Found
ListBox1.List(i, 1) = Cells(Found.Row, 13)
ListBox2.AddItem Found.Row
i = i + 1
Do
Found.Activate
Set Found = Cells.FindNext(After:=ActiveCell)
On Error Resume Next
If Found.Address = FirstAddress Then Exit Do
ListBox1.AddItem Found
ListBox1.List(i, 1) = Cells(Found.Row, 13)
ListBox2.AddItem Found.Row
i = i + 1
Loop
End If
End With
CommandButton1.Caption = "Neue Suche"
End Sub
'Listbox mit den Ergebnissen - auf Klick werden die Details angezeigt
Private Sub ListBox1_Click()
If ListBox1.Value <> "" Then
On Error Resume Next
ListBox2.ListIndex = ListBox1.ListIndex
txtKontoNr = Cells(ListBox2.Value, 1)
txtKontobez = Cells(ListBox2.Value, 2)
txtBuchungstext = Cells(ListBox2.Value, 3)
End If
End Sub
'Bei Doppelklick die Zeile im Datenblatt markieren
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If ListBox1.Value <> "" Then
On Error Resume Next
ListBox2.ListIndex = ListBox1.ListIndex
Rows(ListBox2.Value).Select
End If
End Sub
Private Sub Userform_Activate()
CommandButton1.Caption = "Suche"
End Sub
Wie kann ich nun verhindern, dass eine Zeile mehrmals in die Listbox geschrieben wird? Bin leider nicht sehr fit in VBA
Vielen Dank für die Hilfe
Gruß