本帖最后由 一坨屎吖 于 2021-7-17 19:20 编辑
这个咋vba中用正则表达式提取其实更方便。
附完整代码:Sub 宏1()
Dim re As New RegExp, mat, rng As Range, Match, mat2, Match3, Length, Start
For Each rng In Range("H5:H39")
With re
.Global = 0
.Pattern = "排名第[0-9]*"
Set mat = .Execute(rng)
For Each Match In mat
If IsNumeric(Replace(Match, "排名第", "")) = True Then
If (Replace(Match, "排名第", "")) > 25 Then
With re
.Global = 0
.Pattern = "[0-9]*月5G核心城.*?排名第[0-9]*"
Set mat2 = .Execute(rng)
For Each Match3 In mat2
Start = InStr(rng, Match3)
Length = Len(Match3)
With rng.Characters(Start:=Start, Length:=Length).Font
.Color = -16776961
End With
Next
End With
End If
End If
Next
End With
With re
.Global = 0
.Pattern = "下行平均速率([1-9][0-9]*)+(\.[0-9]{1,3})?"
Set mat = .Execute(rng)
For Each Match In mat
If IsNumeric(Replace(Match, "下行平均速率", "")) = True Then
If (Replace(Match, "下行平均速率", "")) < 750 Then
With re
.Global = 0
.Pattern = "下行平均速率.*?Mbps"
Set mat2 = .Execute(rng)
For Each Match3 In mat2
Start = InStr(rng, Match3)
Length = Len(Match3)
With rng.Characters(Start:=Start, Length:=Length).Font
.Color = -16776961
End With
Next
End With
End If
End If
Next
End With
With re
.Global = 0
.Pattern = "排名第[0-9]*。"
Set mat = .Execute(rng)
For Each Match In mat
If Replace(Replace(Match, "排名第", ""), "。", "") > 25 Then
With re
.Global = 0
.Pattern = "5G时长驻留比.*"
Set mat2 = .Execute(rng)
For Each Match3 In mat2
Start = InStr(rng, Match3)
Length = Len(Match3)
With rng.Characters(Start:=Start, Length:=Length).Font
.Color = -16776961
End With
Next
End With
End If
Next
End With
With re
.Global = 0
.Pattern = "。[0-9]*月.*?高频次.*?。"
Set mat = .Execute(rng)
For Each Match In mat
Start = InStr(rng, Match)
Length = Len(Match)
With rng.Characters(Start:=Start, Length:=Length).Font
.Color = -16776961
End With
Next
End With
Next
End Sub
|