Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1192to1196
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Zwei Bedingungen in UserForm suchen

Zwei Bedingungen in UserForm suchen
Hans
Hallo Leute,
ich habe folgenden Code in einer Userbox.
Aufgabe?
Es wird in der Tabelle Kunden in Spalte C nach dem Kundennamen der per textSearch übergeben wird gesucht und alle Fundstellen in der Userbox angezeigt
Nun möchte dass man zusätzlich nach dem Vornamen suchen kann der in mit textSearch2 übergeben wird.
Der Vorname steht in der Tabelle Kunden in Spalte D
Kann mir da vlt. jemand weiterhelfen?
lg
Hans
Private Sub FillList()
Dim rng As Range
Dim sFirst As String
Dim i As Integer
ListBox2.Clear
ListBox1.AddItem
ListBox1.List(i, 0) = "Name"
ListBox1.List(i, 1) = "| Vorname"
ListBox1.List(i, 2) = "| Straße"
ListBox1.List(i, 3) = "| Ort"
ListBox1.List(i, 4) = "| Telefonnummer"
ListBox1.List(i, 5) = "| Kundenummer"
Set rng = Workbooks("Kunden.xls").Worksheets("Kundenstamm").Range("C:C") _
.Find(What:=txtSearch, LookIn:=xlValues, LookAt:=xlPart, After:=Range("C15000"))
If Not rng Is Nothing Then
sFirst = rng.Address
ListBox2.AddItem
ListBox2.List(i, 0) = rng
ListBox2.List(i, 1) = "| " & rng.Offset(0, 1)
ListBox2.List(i, 2) = "| " & rng.Offset(0, 2)
ListBox2.List(i, 3) = "| " & rng.Offset(0, 3) & " " & rng.Offset(0, 4)
ListBox2.List(i, 4) = "| " & rng.Offset(0, 5)
ListBox2.List(i, 5) = "|"
ListBox2.List(i, 6) = rng.Offset(0, -2)
i = i + 1
Do
Set rng = Workbooks("Kunden.xls").Worksheets("Kundenstamm").Range("C:C").FindNext(After: _
=rng)
If rng.Address = sFirst Then Exit Do
ListBox2.AddItem
ListBox2.List(i, 0) = rng
ListBox2.List(i, 1) = "| " & rng.Offset(0, 1)
ListBox2.List(i, 2) = "| " & rng.Offset(0, 2)
ListBox2.List(i, 3) = "| " & rng.Offset(0, 3) & " " & rng.Offset(0, 4)
ListBox2.List(i, 4) = "| " & rng.Offset(0, 5)
ListBox2.List(i, 5) = "|"
ListBox2.List(i, 6) = rng.Offset(0, -2)
i = i + 1
Loop
End If
If ListBox2.ListCount = 0 Then
Unload Me
MsgBox "Dieser Name wurde nicht gefunden"
Exit Sub
End If
End Sub

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Zwei Bedingungen in UserForm suchen
09.01.2011 22:17:05
Josef

Hallo Hans,
da gibt es mehrere Ansätze, hier einer davon.

Private Sub FillList()
  Dim strSrch1 As String, strSrch2 As String
  Dim vntS1 As Variant, vntS2 As Variant
  Dim lngIndex As Long, lngLast As Long
  
  strSrch1 = IIf(textSearch = "", "*", "*" & textSearch & "*")
  strSrch2 = IIf(textSearch2 = "", "*", "*" & textSearch2 & "*")
  
  ListBox2.Clear
  ListBox1.AddItem "Name"
  ListBox1.List(0, 1) = "| Vorname"
  ListBox1.List(0, 2) = "| Straße"
  ListBox1.List(0, 3) = "| Ort"
  ListBox1.List(0, 4) = "| Telefonnummer"
  ListBox1.List(0, 5) = "| Kundenummer"
  
  
  With Workbooks("Kunden.xls").Sheets("Kundenstamm")
    lngLast = .Cells(.Rows.Count, 3).End(xlUp).Row
    vntS1 = .Range(.Cells(2, 3), .Cells(lngLast, 3))
    vntS2 = .Range(.Cells(2, 4), .Cells(lngLast, 4))
    
    For lngIndex = 1 To UBound(vntS1, 1)
      If LCase(vntS1(lngIndex, 1)) Like LCase(strSrch1) And LCase(vntS2(lngIndex, 1)) Like LCase(strSrch2) Then
        ListBox2.AddItem .Cells(lngIndex + 1, 3)
        ListBox2.List(ListBox2.ListCount - 1, 1) = "| " & .Cells(lngIndex + 1, 4)
        ListBox2.List(ListBox2.ListCount - 1, 2) = "| " & .Cells(lngIndex + 1, 5)
        ListBox2.List(ListBox2.ListCount - 1, 3) = "| " & .Cells(lngIndex + 1, 6) & " " & .Cells(lngIndex + 1, 7)
        ListBox2.List(ListBox2.ListCount - 1, 4) = "| " & .Cells(lngIndex + 1, 8)
        ListBox2.List(ListBox2.ListCount - 1, 5) = "|"
        ListBox2.List(ListBox2.ListCount - 1, 6) = .Cells(lngIndex + 1, 1)
      End If
    Next
    If ListBox2.ListCount = 0 Then ListBox2.AddItem "Name nicht gefunden!"
  End With
End Sub

Gruß Sepp

Anzeige
AW: Zwei Bedingungen in UserForm suchen
09.01.2011 22:27:52
Hans
WOW
Sepp ich danke dir .. sorgar verstehe ich alles.
Danke
Gruß Hans

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige