AW: Einzelne Buchstaben einer Zelle per VBA einfärben
15.01.2025 14:44:36
Raimund
Hi Ina
Versuche es damit. Sheet1 umbenennen
Sub FormatTextInCells()
Dim cell As Range
Dim searchRange As Range
Dim startPos As Long
Dim textLength As Long
' Definiere den Bereich, der durchsucht werden soll
Set searchRange = ThisWorkbook.Sheets("Sheet1").Range("B1:B250") ' Ändere "Sheet1" entsprechend deinem Blattnamen
' Durchlaufe jede Zelle im definierten Bereich
For Each cell In searchRange
If Not IsEmpty(cell.Value) Then
' Suche nach "S.S.C."
startPos = InStr(cell.Value, "S.S.C.")
If startPos > 0 Then
textLength = Len("S.S.C.")
cell.Characters(startPos, textLength).Font.Color = RGB(255, 0, 0) ' Rot
End If
' Suche nach "S.C."
startPos = InStr(cell.Value, "S.C.")
If startPos > 0 Then
textLength = Len("S.C.")
cell.Characters(startPos, textLength).Font.Color = RGB(255, 165, 0) ' Orange
End If
' Suche nach "L"
startPos = InStr(cell.Value, "L")
If startPos > 0 Then
textLength = Len("L")
cell.Characters(startPos, textLength).Font.Color = RGB(255, 0, 0) ' Rot
End If
End If
Next cell
End Sub
Oder mit dem aktiven Blatt:
Sub FormatTextInCells()
Dim cell As Range
Dim searchRange As Range
Dim startPos As Long
Dim textLength As Long
' Definiere den Bereich, der durchsucht werden soll
Set searchRange = ActiveSheet.Range("B1:B250") ' Verwendet das aktive Arbeitsblatt
' Durchlaufe jede Zelle im definierten Bereich
For Each cell In searchRange
If Not IsEmpty(cell.Value) Then
' Suche nach "S.S.C."
startPos = InStr(cell.Value, "S.S.C.")
If startPos > 0 Then
textLength = Len("S.S.C.")
cell.Characters(startPos, textLength).Font.Color = RGB(255, 0, 0) ' Rot
End If
' Suche nach "S.C."
startPos = InStr(cell.Value, "S.C.")
If startPos > 0 Then
textLength = Len("S.C.")
cell.Characters(startPos, textLength).Font.Color = RGB(255, 165, 0) ' Orange
End If
' Suche nach "L"
startPos = InStr(cell.Value, "L")
If startPos > 0 Then
textLength = Len("L")
cell.Characters(startPos, textLength).Font.Color = RGB(255, 0, 0) ' Rot
End If
End If
Next cell
End Sub
Gruss
Raimund