打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
EXcel VBA 批量查找关键词,并着色

Sub Findcolour()

'

' Findcolour Macro

' 宏由 Haifeng 录制,时间: 2021/10/07

'

'

mword = Trim(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

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
更改文本当中出现的数字或字母的字体
将多个单元格合并,保留原单元格颜色
Excel-VBA查找字符并调整为上标
汉字乘法口诀VBA
【leetcode 300】最长上升子序列 O(nlogn)解法
如何用VBA将单元格中部分文字改变颜色?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服