Dim I&, J&, N%, B%, Ra As Range
Set Ra = ActiveSheet.UsedRange
Application.ScreenUpdating = False
Ra.Font.ColorIndex = -4105
N = 3
For I = 1 To Ra.Count - 1
B = 0
If N > 18 Then N = 3
A = Ra(I).Font.ColorIndex
If Ra(I).Font.ColorIndex = -4105 And Not IsEmpty(Ra(I)) Then
For J = I + 1 To Ra.Count
If Ra(I) = Ra(J) Then Ra(J).Font.ColorIndex = N: B = 1
Next
If B = 1 Then Ra(I).Font.ColorIndex = N: N = N + 1
End If
Next
Application.ScreenUpdating = True
代码运行后效果如下图。