如何用VBA编写,把工作表中相同字符串标记上颜色,非常感谢!

如题所述

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

代码运行后效果如下图。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-28
条件格式就行了,用不着VBA
第2个回答  2014-04-28
他手机都是
相似回答