Text wird nach WIEDERHOLEN nicht als Text erkannt
28.01.2006 12:32:20
Michael
ich habe folgendes Problem:
Mit nachfolgendem Makro färbe ich in Spalte B genau die Buchstaben/Wörter um, die in Zelle A4 vorgegeben werden. In Spalte B steht nur Text. Das funktioniert auch ganz prima.
Doch wenn ich mit der Funktion WIEDERHOLEN ider INDEX einen Text in Spalte B eintragen lasse, dann wird nichts mehr markiert.
Die Zellen habe ich als als Text formatiert. Woran liegt das und kann ? Gibt es eine Lösung oder ist es nicht machbar?
Hier der VBA-Code:
Option Explicit
Sub ColorCharacters()
Dim strFind As String, strText As String
Dim lngRow As Long, lngLast As Long, intIndex As Integer, intLen As Integer
strFind = LCase(Trim$(Range("A4").Text))
intLen = Len(strFind)
If Len(strFind) = 0 Then Exit Sub
lngLast = Cells(Rows.Count, 2).End(xlUp).Row
Range("B:B").Font.ColorIndex = xlAutomatic
For lngRow = 1 To lngLast
intIndex = 0
If Len(Cells(lngRow, 2)) > 0 Then
strText = LCase(Cells(lngRow, 2))
intIndex = InStr(1, strText, strFind)
If intIndex > 0 Then
Do
Cells(lngRow, 2).Characters(intIndex, intLen).Font.ColorIndex = 3
intIndex = InStr(intIndex + intLen, strText, strFind)
Loop While intIndex > 0
End If
End If
Next
End Sub
Über eine Antwort würde ich mich freuen.
Gruss
Michael