|
Sub HighlightText()
Dim searchText As String
Dim searchRange As Range
Dim cell As Range
'设置要搜索的文本和范围
searchText = InputBox("请输入要搜索的文本:")
Set searchRange = ActiveSheet.UsedRange '搜索整个工作表的使用范围
'遍历每个单元格并查找文本
Application.ScreenUpdating = False '关闭屏幕更新以提高性能
For Each cell In searchRange
If InStr(1, cell.Value, searchText, vbTextCompare) > 0 Then
cell.Font.Color = RGB(255, 0, 0) '将找到的文本设置为红色
End If
Next cell
Application.ScreenUpdating = True '重新打开屏幕更新
MsgBox "搜索完成,已突出显示所有包含指定文本的单元格。"
End Sub
|
|