vba中怎么遍历单元格中所有字符串

vba中怎么把单元格中所有字符串带reqdate(忽略大小写)的标红,小白一个,我的代码买次只遍历一次,因为只有一个if语句。

答:

Sub Demo()
    Dim rng As Range
    Dim mMatches As Object, mMatch As Object
    For Each rng In Range("E1:E300")
        With CreateObject("VBSCRIPT.REGEXP")
            .Global = True
            .Pattern = "reqdate"
            .IgnoreCase = True
            Set mMatches = .Execute(rng.Text)
            For Each mMatch In mMatches
                rng.Characters(mMatch.FirstIndex + 1, 7).Font.ColorIndex = 3
            Next
        End With
    Next
End Sub

实测效果图:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-01-25

i=instr(cells(6,1),"-")
j=len(cells(6,1))-i
cells(6,7)=mid(cells(6,1),i,j)

相似回答