我需要僅爲自動着色文本的代碼。具體來說,我有乾淨的文本,然後是藍色和粗體的文本。我希望乾淨文本變成紅色,粗體和刪除線。這是我正在使用的代碼,整個單元格都是乾淨的,藍色的粗體文本變成紅色,粗體和直線。Excel VBA僅爲以前未着色的文本着色
Sub KeepBlueBold()
'keeps bluebold cell
Dim Cell As Range
For Each Cell In Selection
KeepBlueAddRed Cell
Next Cell
End Sub
Sub KeepBlueAddRed(Cell As Range)
Dim iCh As Integer
For iCh = 1 To Len(Cell)
With Cell.Characters(iCh, 1)
If .FOnt.ColorIndex <> 1 Then
Text = Text & .Text
End If
End With
Next iCh
Cell.Value = Text
Cell.Characters.FOnt.Strikethrough = True
Cell.Characters.FOnt.Bold = True
Cell.Characters.FOnt.ColorIndex = 3
End Sub
您是否在任何給定的單元格中使用了混合格式? –
查找和替換不適合? – pnuts