excel查找关键字变色
答案:2 悬赏:0 手机版
解决时间 2021-03-18 19:21
- 提问者网友:欺烟
- 2021-03-18 06:59
因为表格中有很多字词,只要查找的那一个字或是词变色,不要整个单元格变色
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-03-18 07:24
Sub search()
mword = InputBox("请输入关键字:")
n = Len(mword)
Cells.Font.Color = 0
Cells.Interior.Color = xlNone
With ActiveSheet.Cells
Set c = .Find(mword, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Interior.Color = RGB(255, 255, 0)
n1 = InStr(c.Value, mword)
If n1 = 1 Then
c.Characters(Start:=1, Length:=n).Font.Color = 255
c.Characters(Start:=n + 1, Length:=Len(c.Value) - n).Font.Color = 0
ElseIf n1 + n = Len(c.Value) Then
c.Characters(Start:=1, Length:=Len(c.Value) - n).Font.Color = 0
c.Characters(Start:=Len(c.Value) - n + 1, Length:=n).Font.Color = 255
Else
c.Characters(Start:=1, Length:=n1 - 1).Font.Color = 0
c.Characters(Start:=n1, Length:=n).Font.Color = 255
c.Characters(Start:=n1 + n + 1, Length:=Len(c.Value) - n1 - n).Font.Color = 0
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
包含的关键字的单元格会变成黄色,关键字会变成红色。
mword = InputBox("请输入关键字:")
n = Len(mword)
Cells.Font.Color = 0
Cells.Interior.Color = xlNone
With ActiveSheet.Cells
Set c = .Find(mword, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Interior.Color = RGB(255, 255, 0)
n1 = InStr(c.Value, mword)
If n1 = 1 Then
c.Characters(Start:=1, Length:=n).Font.Color = 255
c.Characters(Start:=n + 1, Length:=Len(c.Value) - n).Font.Color = 0
ElseIf n1 + n = Len(c.Value) Then
c.Characters(Start:=1, Length:=Len(c.Value) - n).Font.Color = 0
c.Characters(Start:=Len(c.Value) - n + 1, Length:=n).Font.Color = 255
Else
c.Characters(Start:=1, Length:=n1 - 1).Font.Color = 0
c.Characters(Start:=n1, Length:=n).Font.Color = 255
c.Characters(Start:=n1 + n + 1, Length:=Len(c.Value) - n1 - n).Font.Color = 0
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub
包含的关键字的单元格会变成黄色,关键字会变成红色。
全部回答
- 1楼网友:迷人又混蛋
- 2021-03-18 08:37
最好的办法是:
(1)选中所有单元格(Ctrl+A)
(2)选“条件格式”
(3)再选“条件格式”的“突出显示单元格规则”中的“等于”
(4)在“等于”对话框中输入你想查找的值
(5)按“确定”
这时,与你查找内容相等的单元格为默认显示为“浅红色填充色深红色文本”。如果想改变突出显示的颜色,在刚才第(4)步中的对话框中设置。
如果想取消突出显示,则在“条件格式”的“清除规则”中进行操作。或用“Ctrl+Z”对刚才的操作进行取消。
祝你好运。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯