高亮关键字

Sub test()
  Dim r%, i%
  Dim arr, brr
  Dim reg As New RegExp
  With reg
    .Global = True
    .Pattern = "7"   '关键字
    
  End With
  With Worksheets("sheet1")
    r = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
    c = .UsedRange.Find(what:="*", LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
    .UsedRange.Font.ColorIndex = 0
    For i = 1 To r
      For j = 1 To c
        If Len(.Cells(i, j)) <> 0 Then
          Set mh = reg.Execute(.Cells(i, j).Value)
          If mh.Count > 0 Then
            For k = 0 To mh.Count - 1
              .Cells(i, j).Characters(Start:=mh(k).FirstIndex + 1, Length:=mh(k).Length).Font.ColorIndex = 3 '设置颜色
              .Cells(i, j).Characters(Start:=mh(k).FirstIndex + 1, Length:=mh(k).Length).Font.Bold = True  ' 字体加粗
              .Cells(i, j).Characters(Start:=mh(k).FirstIndex + 1, Length:=mh(k).Length).Font.Size = 24  '设置字体大小为24磅
              
            Next
          End If
        End If
      Next
    Next
  End With
End Sub

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值