【VBA_选择区域的关键词更改颜色】

【VBA_选择区域的关键词更改颜色】_第1张图片

Private Sub CommandButtonl_Click()
Cells.Font.ColorIndex = 1
End Sub
Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range, i As Integer
Dim T As String
Dim C As Integer
For Each rng In Selection
T = "河北"
C = 3
i = 1
Do While InStr(i, rng, T) > 0
rng.Characters(InStr(i, rng, T), Len(T)).Font.ColorIndex = C
i = InStr(i, rng, T) + 1
Loop
Next
End Sub

效果【VBA_选择区域的关键词更改颜色】_第2张图片

你可能感兴趣的:(excel)