AW: Suchtreffer anders darstellen
07.02.2021 09:45:36
Robert
Hollo Ullrich
Wenn ich deine Beispieldatei sehe ist mein Vorschlag vielleicht zu einfach. Hat man mir hier im Forum gemacht und geht für meine Belange gut und tut auch den Suchbegriff hervorheben. Muss mit Subcommandbutton gesteuert werden.
Private Sub CommandButton3_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
LG Robert