分享

excel-vba 查找 标色 替换

 随心所欲2019OK 2019-02-16

Sub 查找关键字标色()
    Dim r As Range, s As String, sz
   
    sz = InputBox("请输入 要查找的内容")
    Set r = Cells.Find(sz, LookAt:=xlWhole, SearchOrder:=xlRows)
    If Not r Is Nothing Then
        s = r.Address
        Do
            r.Interior.Color = vbRed
            Set r = Cells.FindNext(r)
        Loop While r.Address <> s
    End If
End Sub

Sub 查找关键字替换颜色()
    Dim cz, th
    cz = InputBox("请输入查找内容")
    th = InputBox("请输入替换内容")
   
    Application.ReplaceFormat.Interior.Color = vbGreen
      
    Cells.Replace What:=cz, Replacement:=th, LookAt:=xlWhole, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多