再精简一点 Sub AddColor() Set d = CreateObject("Scripting.Dictionary") i = 2 Z = [B9999].End(xlUp).Row For i = 2 To Z If Not d.Exists(Cells(i, 2).Value) Then d.Add Cells(i, 2).Value, _ RGB(155 + Rnd * 100, 155 + Rnd * 100, 155 + Rnd * 100) Cells(i, 1).Resize(1, 2).Interior.Color = d(Cells(i, 2).Value) Next i End Sub
Sub AddColor() Set d = CreateObject("Scripting.Dictionary") i = 2 Z = [B9999].End(xlUp).Row For i = 2 To Z If Not d.Exists(Cells(i, 6).Value) Then d.Add Cells(i, 6).Value, _ RGB(155 + Rnd * 100, 155 + Rnd * 100, 155 + Rnd * 100) Cells(i, 1).Resize(1, 6).Interior.Color = d(Cells(i, 6).Value) Next i End Sub
Sub AddColor() Set d = CreateObject("Scripting.Dictionary") i = 2 Z = [B9999].End(xlUp).Row For i = 2 To Z If Not d.Exists(Cells(i, 2).Value) Then d.Add Cells(i, 2).Value, _ RGB(155 + Rnd * 100, 155 + Rnd * 100, 155 + Rnd * 100) Cells(i, 1).Resize(1, 6).Interior.Color = d(Cells(i, 2).Value) Next i End Sub
Sub ccp1111() Set d = CreateObject("Scripting.Dictionary") k = [A1048576].End(xlUp).Row For i = 2 To k If Not d.Exists(Cells(i, 1).Value) Then d(Cells(i, 1).Value) = i Mod 56 End If Cells(i, 1).Resize(1, 2).Interior.ColorIndex = d.Item(Cells(i, 1).Value) Next Set d = Nothing End Sub