原来你不会VBA,那我教你用吧,按ALT+F11打开vba编辑器,插入模块,把下面的代码贴上,保存退出,然后在EXCEL中添加一个按钮,右键单击按钮——指定宏,指定“标记查找文字”宏,然后单击按钮就可以运行程序了
Sub 标记查找文字()
Dim CaZhao As String
Dim i, j, l, k As Long
Dim p As String
Dim kk()
Application.ScreenUpdating = False
CaZhao = Application.InputBox("请输入要查找的文字", "标记查找文字")
k = Len(CaZhao)
For i = 1 To Cells.Find("*", , , , 1, 2).Row
For j = 1 To Cells.Find("*", , , , 2, 2).Column
p = Cells(i, j).Value
If p <> "" Then
Cells(i, j).Select
With ActiveCell.Characters.Font
.FontStyle = False
.ColorIndex = 1
.Underline = False
End With
If InStr(Cells(i, j).Value, CaZhao) <> 0 Then
n = 0
Do
l = InStrRev(p, CaZhao)
If l = 0 Then Exit Do
ReDim Preserve kk(n)
kk(n) = l
n = n + 1
p = Left(p, l - 1)
Loop While l <> 0
For s = LBound(kk) To UBound(kk)
With ActiveCell.Characters(Start:=kk(s), Length:=k).Font
.FontStyle = "加粗 倾斜"
.ColorIndex = 3
.Underline = xlUnderlineStyleSingle
End With
Next
End If
End If
Next
Next
Application.ScreenUpdating = True
End Sub
试试条件格式
示例:当指定区域内有数值等于H1单元格的值时标记为红色
‘VBA高人来也,使用如下自定义函数:
‘测试过了,完全好用!
Sub test()
Dim cc As Range
Dim MyshName As String
Dim MyRng As String
Dim MySearch As String
MyshName = "Sheet1"
'定义要应用的表名
MyRng = "A1:A100"
'定义要应用的单元格区域
MySearch = "ang"
'定义要查找的关键字
For Each cc In ThisWorkbook.Worksheets(MyshName).Range(MyRng)
If InStr(1, cc.Value, MySearch) Then
cc.Characters(Start:=InStr(1, cc.Value, MySearch), Length:=Len(MySearch)).Font.ColorIndex = 3
End If
Next
End Sub
据我所知,目前版本还没有取字体或置字体颜色的函数(自定义除外),另想办法吧,比方说在辅助列中通过查找函数找出相应的词。这要看你需要实现什么样的功能。