Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 5825|回复: 6

[已解决]求助,如何只高亮所有关键词字体,难点在于有的单元格内关键词出现多次,并且位置随机

[复制链接]
发表于 2016-10-31 09:31 | 显示全部楼层 |阅读模式
求助,如何只高亮所有关键词字体,难点在于有的单元格内关键词出现多次,并且位置随机
最佳答案
2016-10-31 10:37
Sub test()
    Dim str, reg, match, matchs, x
    Set reg = CreateObject("VBScript.RegExp")
    reg.Global = True
    str = "关键词"

    For Each x In ActiveSheet.UsedRange
        If InStr(x, str) Then
            x.Font.ColorIndex = xlAutomatic
            reg.Pattern = str
            Set matchs = reg.Execute(x)
            For Each match In matchs
                x.Characters(Start:=match.firstindex + 1, Length:=match.Length).Font.ColorIndex = 3
            Next
        End If
    Next
End Sub

求助,如何只高亮所有关键词字体,难点在于有的单元格内关键词出现多次,并且位置随机

求助,如何只高亮所有关键词字体,难点在于有的单元格内关键词出现多次,并且位置随机

求助,如何只高亮所有关键词字体,难点在于有的单元格内关键词出现多次,并且位置随机.rar

14.51 KB, 下载次数: 23

求助,如何只高亮所有关键词字体,难点在于有的单元格内关键词出现多次,并且位置随机

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-10-31 10:20 | 显示全部楼层
本帖最后由 砂海 于 2016-10-31 10:22 编辑

Sub 宏1()

Dim x

x = Application.Find("", Range("B17"))

    With ActiveCell.Characters(Start:=x, Length:=1).Font   
        .Name = "Arial Unicode MS"
        .FontStyle = "常规"
        .Size = 20
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .Color = -16776961
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With

End Sub

================上为局部
================以下整体思路
On Error GoTo 单个完成
    'for 区域循环
单个开始:
            套用上面程序 '查找不到会出错跳转
    GoTo 单个开始
单个完成:
    Next

回复

使用道具 举报

发表于 2016-10-31 10:33 | 显示全部楼层
本帖最后由 su45 于 2016-10-31 10:34 编辑



2164.zip (16.65 KB, 下载次数: 28)

评分

参与人数 1 +1 收起 理由
youxianwei + 1 很给力

查看全部评分

回复

使用道具 举报

发表于 2016-10-31 10:37 | 显示全部楼层    本楼为最佳答案   
Sub test()
    Dim str, reg, match, matchs, x
    Set reg = CreateObject("VBScript.RegExp")
    reg.Global = True
    str = "关键词"

    For Each x In ActiveSheet.UsedRange
        If InStr(x, str) Then
            x.Font.ColorIndex = xlAutomatic
            reg.Pattern = str
            Set matchs = reg.Execute(x)
            For Each match In matchs
                x.Characters(Start:=match.firstindex + 1, Length:=match.Length).Font.ColorIndex = 3
            Next
        End If
    Next
End Sub

评分

参与人数 1 +1 收起 理由
youxianwei + 1 很给力

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2016-10-31 12:47 | 显示全部楼层
多谢大家的帮助
回复

使用道具 举报

 楼主| 发表于 2016-10-31 13:02 | 显示全部楼层
爱疯的答案速度更快,原理菜鸟我慢慢消化,再次谢谢大家帮助
回复

使用道具 举报

 楼主| 发表于 2016-11-1 11:06 | 显示全部楼层

1

本帖最后由 youxianwei 于 2016-11-1 11:22 编辑

?????????
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-18 22:17 , Processed in 0.332797 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表