Suchfunktion per Makro findet keine Daten
28.02.2024 17:07:43
Robert Pilz
Habe mal wieder ein Problem bei welchen ich Eure Hilfe bräuchte.
Habe einen Code der über CommandButton-Steuerelement ausgeführt wird. Funktioniert auch sehr gut wenn ich einzelne Worte, oder Zahlen suchen. Aber ein komplettes Datum wie z.B. 16.03.2024 wird einfach ignoriert und es kommt "kein Ergebnis gefunden".
Woran kann das liegen? Setze mal den Code und eine Beispieldatei hier herein.
Vielleicht ist Jemand so lieb und kann mir helfen.
Für Eure Bemühungen danke ich Euch im voraus.
LG Robert
Private Sub CommandButton1_Click()
Dim strSearch As String, strFirstAddress As String
Dim objCell As Range, objWorksheet As Worksheet
Dim blnAbort As Boolean, blnFound As Boolean
Dim lngOldColor As Long
strSearch = InputBox("Suchbegriff:", "Suche nach...")
If strSearch > vbNullString Then
Do
For Each objWorksheet In ThisWorkbook.Worksheets
Set objCell = objWorksheet.Cells.Find(What:=strSearch, _
LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
If Not objCell Is Nothing Then
strFirstAddress = objCell.Address(External:=True)
blnFound = True
Do
Call Application.Goto(Reference:=objCell)
With objCell.Interior
lngOldColor = .Color
.Color = RGB(155, 194, 230)
End With
If MsgBox("Weitersuchen?", vbQuestion Or vbYesNo, "Abfrage") = vbNo Then
objCell.Interior.Color = lngOldColor
blnAbort = True
Exit Do
End If
objCell.Interior.Color = lngOldColor
Set objCell = objWorksheet.Cells.FindNext(After:=objCell)
If objCell Is Nothing Then Exit Do
Loop Until objCell.Address(External:=True) = strFirstAddress
End If
If blnAbort Then Exit For
Next
If objCell Is Nothing And Not blnFound Then
Call MsgBox("Suchbegriff nicht gefunden.", vbExclamation, "Hinweis")
Exit Do
ElseIf Not blnAbort Then
If MsgBox("Letze Fundstelle." & vbLf & vbLf & "Nochmal von vorne?", _
vbQuestion Or vbYesNo, "Abfrage") = vbNo Then Exit Do
End If
Loop Until blnAbort
End If
End Sub
https://www.herber.de/bbs/user/167395.xlsm