VBA Suche
22.01.2013 14:47:54
Erol
habe ein für Euch bestimmt nur kleines Such-Problem. ,)
Derzeit rufe ich eine UserForm auf, in der mir die Suchergebnisse(Suchwert aus einer textbox)in einer Listbox angezeigt werden.
Nun möchte ich gern eine erweiterte Suche einbauen, in der nach 2 Suchkreterien in Abhängigkeit gesucht wird. (Also nach Werten aus TextBox300 und TextBox301)
Könnt Ihr mir da weiterhelfen?
Hier der Code, den ich derzeit für die einfache Suche verwende:
Private Sub CommandButton1_Click() ' Suchen
Dim rng As Range
Dim strFirst As String
Dim vtmp() As Long
Dim tntC As Integer
If Len(Trim(TextBox300)) = 0 Then Exit Sub
ListBox1.Clear
For IntC = 1 To 22
Controls("TextBox" & IntC) = ""
Next
ReDim vtmp(0)
With Sheets("Tabelle1")
Set rng = .Range("B:V").Find(What:=TextBox300, LookAt:=xlPart)
If Not rng Is Nothing Then
strFirst = rng.Address
Do
If Not (IsNumeric(Application.Match(rng.Row, vtmp, 0))) Then
ReDim Preserve vtmp(UBound(vtmp) + 1)
vtmp(UBound(vtmp)) = rng.Row
ListBox1.AddItem .Cells(rng.Row, 2)
ListBox1.List(ListBox1.ListCount - 1, 1) = .Cells(rng.Row, 3)
ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(rng.Row, 4)
ListBox1.List(ListBox1.ListCount - 1, 3) = .Cells(rng.Row, 5)
ListBox1.List(ListBox1.ListCount - 1, 4) = .Cells(rng.Row, 6)
ListBox1.List(ListBox1.ListCount - 1, 5) = .Cells(rng.Row, 7)
ListBox1.List(ListBox1.ListCount - 1, 6) = .Cells(rng.Row, 8)
ListBox1.List(ListBox1.ListCount - 1, 7) = rng.Row
End If
Set rng = .Range("B:V").FindNext(rng)
Loop While Not rng Is Nothing And rng.Address strFirst
End If
End With
If ListBox1.ListCount > 0 Then
ListBox1.ListIndex = 0
Label14.Caption = "Trefferliste"
Else
Label14.Caption = "Keinen Eintrag gefunden!"
End If
Set rng = Nothing
End Sub