habe folgendes Makro im Forum bzw. Google gefunden. Es klappt soweit
für das Suchen in der Listbox.
Leider kommt bleibt das Makro bei der Zeile stehen:
' Me.ListBox1.List(iLiBo, 10) = Format(WkSh.Range("K" & rZelle.Row).Value, "YY")
die anderen Daten werden eingelesen.
Habe also die Zeilen von K bis AL ausgeklammert.
Wo ist da der Fehler, habe Textbox1 und 2 für das Suchen.
Textbox für Spalte 3 "Firmennamen" und Textbox 2 für das Suchen "Namen".
Im Makro waren vorher 3 Textboxen vorgesehen, hatte soweit Textmäßig gelöscht.
Vielleicht hat jemand eine IDEEEEEE, ich leider nicht, fummel jetzt schon
4h darum...
mfg Walter
Private Sub CommandButton14_Click()
Dim WkSh As Worksheet
Dim rZelle As Range
Dim sFundst As String
Dim sSuchbegriff As String
Dim iSpalte As Integer
Dim iLiBo As Integer
Dim lZeile As Long
Dim lLetzte As Long
Dim sTyp As String
Me.ListBox1.RowSource = ""
'Exit Sub
TextBox1.Value = Trim$(TextBox1.Value)
TextBox2.Value = Trim$(TextBox2.Value)
If TextBox1.Value = "" And _
TextBox2.Value = "" Then
MsgBox "Ohne Suchbegiff wird die Suche schwierig werden!" & Chr(10) & _
"Bitte geben Sie wenigstens einen Suchbegriff ein - danke.", _
48, " Hinweis für " & Application.UserName
TextBox1.SetFocus
Exit Sub
ElseIf TextBox1.Value "" Then
sSuchbegriff = TextBox1.Value & "*"
iSpalte = 3
ElseIf TextBox2.Value "" Then
sSuchbegriff = TextBox2.Value
iSpalte = 8
End If
Set WkSh = ThisWorkbook.Worksheets("Datenbank")
With WkSh.Columns(iSpalte)
' Set rZelle = .Find(What:=sSuchbegriff, LookAt:=xlPart, LookIn:=xlValues, _
After:=.Cells(.Cells.Count))
'--- hiermit wird nur nach dem 1. Buchstaben gesucht ---
Set rZelle = .Find(What:=sSuchbegriff, LookAt:=xlWhole, LookIn:=xlValues, _
After:=.Cells(.Cells.Count))
If Not rZelle Is Nothing Then
sFundst = rZelle.Address
Do
If iSpalte = 1 Then
If TextBox1.Value "" Then
If InStr(LCase(WkSh.Range("A" & rZelle.Row)), LCase(TextBox1.Value)) > 0 Then
GoSub ListBox_fuellen
End If
Else
GoSub ListBox_fuellen
End If
Else
GoSub ListBox_fuellen
End If
Set rZelle = .FindNext(rZelle)
Loop While Not rZelle Is Nothing And rZelle.Address sFundst
Else
If iSpalte = 3 And TextBox1.Value "" Then
MsgBox "Zu den Begriffen """ & sSuchbegriff & " / " & TextBox1.Value & _
""" wurde nichts gefunden.", _
48, " Hinweis für " & Application.UserName
TextBox1.SetFocus
Else
MsgBox "Der Begriff """ & sSuchbegriff & """ wurde nicht gefunden.", _
48, " Hinweis für " & Application.UserName
If iSpalte = 8 And TextBox2.Value "" Then
MsgBox "Zu den Begriffen """ & sSuchbegriff & " / " & TextBox2.Value & _
""" wurde nichts gefunden.", _
48, " Hinweis für " & Application.UserName
TextBox2.SetFocus
Else
' MsgBox "Der Begriff """ & sSuchbegriff & """ wurde nicht gefunden.", _
48, " Hinweis für " & Application.UserName
End If
End If
End If
End With
Set rZelle = Nothing
Exit Sub
ListBox_fuellen:
Me.ListBox1.AddItem " "
Me.ListBox1.List(iLiBo, 0) = WkSh.Range("A" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 1) = WkSh.Range("B" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 2) = WkSh.Range("C" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 3) = WkSh.Range("D" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 4) = WkSh.Range("E" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 5) = WkSh.Range("F" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 6) = WkSh.Range("G" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 7) = WkSh.Range("H" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 8) = WkSh.Range("I" & rZelle.Row).Value
Me.ListBox1.List(iLiBo, 9) = Format(WkSh.Range("J" & rZelle.Row).Value, "dd.mm.yyyy")
' Me.ListBox1.List(iLiBo, 10) = Format(WkSh.Range("K" & rZelle.Row).Value, "YY")
' Me.ListBox1.List(iLiBo, 11) = WkSh.Range("L" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 12) = WkSh.Range("M" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 13) = WkSh.Range("N" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 14) = WkSh.Range("O" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 15) = WkSh.Range("P" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 16) = WkSh.Range("Q" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 17) = WkSh.Range("R" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 18) = WkSh.Range("S" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 19) = WkSh.Range("T" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 20) = WkSh.Range("U" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 21) = WkSh.Range("V" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 22) = WkSh.Range("W" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 23) = WkSh.Range("X" & rZelle.Row).Value
' Me.ListBox1.List(iLiBo, 24) = WkSh.Range("Y" & rZelle.Row).Value
iLiBo = iLiBo + 1
Return
Exit Sub
End Sub