|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2017-2-19 13:59
|
显示全部楼层
Sub 自动更改指定文字颜色及字体()
Dim arr, brr, x&, y&, z&, d As Object
Application.ScreenUpdating = False
Set d = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
arr = .Range("b18").CurrentRegion
brr = .Range("c14").CurrentRegion
For z = 1 To UBound(brr)
s1 = brr(z, 1): a = Len(s1)
For x = 1 To UBound(arr)
s = arr(x, 2)
For y = 1 To Len(s)
ss = Mid(s, y, a)
If ss = s1 Then
If Not d.exists(y) Then
d(y) = a
End If
End If
Next y
wz = d.keys: cd = d.items
For i = 0 To UBound(wz)
With .Cells(17 + x, 2).Characters(Start:=wz(i), Length:=cd(i)).Font
If z = 1 Then
.ColorIndex = 5
ElseIf z = 2 Then
.ColorIndex = 4
Else
.ColorIndex = 3
End If
.Bold = True
End With
Next i
d.RemoveAll
Next x
Next z
End With
End Sub
|
|