hier mal eine Möglichkeit...
15.09.2009 10:26:53
Tino
Hallo,
versuche es mal hiermit.
Sub FarbeText(sZelle As Range, sBegriff As String, iColor As Integer, booCase As Boolean)
Dim objRegExp As Object, oMatch As Object
Set objRegExp = CreateObject("vbscript.regexp")
With objRegExp
.Global = True
.Pattern = sBegriff
.IgnoreCase = Not booCase
Set oMatch = .Execute(sZelle.Text)
End With
For Each oMatch In oMatch
sZelle.Characters(Start:=oMatch.FirstIndex + 1, Length:=oMatch.Length).Font.ColorIndex = iColor
Next oMatch
Set objRegExp = Nothing
End Sub
Sub Beispiel()
Dim Bereich As Range
'Bereich anpassen
Set Bereich = Range("A7", Cells(Rows.Count, 1).End(xlUp))
Bereich.Font.ColorIndex = xlAutomatic
For Each Bereich In Bereich
If Bereich.Text <> "" Then
'Zelle; Suchbegriff; Farbindex; Groß u. Kleinschreibung beachten True = Ja
FarbeText Bereich, "Hallo", 3, False
End If
Next Bereich
End Sub
Gruß Tino