|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub xx()
Dim i, j, j1, j2, j3, j4, k, k1, l%, l1%, l2%, reg, reg1
[A23].CurrentRegion.Font.Color = 7
Set reg = CreateObject("VBscript.regexp")
Set reg1 = CreateObject("VBscript.regexp")
reg.Pattern = "[0-9]+"
reg1.Pattern = "[A-Z]+"
reg.Global = True
reg1.Global = True
For i = [A65536].End(xlUp).Row To 35 Step -1
Set j = reg1.Execute(Cells(i, 1)) '列数
Set j1 = reg.Execute(Cells(i, 2)) '单元格的数值位置
Set j2 = reg.Execute(Range(Cells(i, 1))) '位置开始
Set j3 = reg.Execute(Cells(28, 1)) '待循环的行数
j4 = Range("a1:" & Cells(i, 1)).Columns.Count - Cells(32, 1) '待查找的列数
For k = 1 To j1.Count
For k1 = j3(0) To j3(1) '循环行数
l = j2(j1(k - 1) - 1) '等于
l2 = j2(j1(k - 1) - 1) + 1 + Cells(26, 1) - 1 '大于
l1 = j2(j1(k - 1) - 1) - Cells(26, 1) '小于
If Cells(24, 1) = "等于" And Cells(26, 1) = "0" Then
If InStr(1, Cells(k1, j4), l, vbTextCompare) > 0 Then
Cells(k1, j4).Characters(InStr(1, Cells(k1, j4), l, vbTextCompare) - 1, Len(l) + 1).Font.Color = vbRed
End If
ElseIf Cells(24, 1) = "小于" Then
If InStr(1, Cells(k1, j4), l1, vbTextCompare) > 0 Then
Cells(k1, j4).Characters(InStr(1, Cells(k1, j4), l1, vbTextCompare) - 1, Len(l1) + 1).Font.Color = vbRed
End If
ElseIf Cells(24, 1) = "大于" Then
If InStr(1, Cells(k1, j4), l2, vbTextCompare) > 0 Then
Cells(k1, j4).Characters(InStr(1, Cells(k1, j4), l2, vbTextCompare) - 1, Len(l2) + 1).Font.Color = vbRed
End If
End If
Next
Next
Next
End Sub |
评分
-
1
查看全部评分
-
|