Sub ColorizeRowsBasedOnColumnValues()
Dim rng As Range
Dim cell As Range
Dim colorIndex As Integer
Dim dict As Object
Set rng = Application.InputBox("请选择包含数据的范围:", Type:=8)
Set dict = CreateObject("Scripting.Dictionary")
colorIndex = 10
Application.ScreenUpdating = False
For Each cell In rng
If Not dict.Exists(cell.Value) Then
dict.Add cell.Value, colorIndex
colorIndex = colorIndex + 1
If colorIndex > 56 Then
colorIndex = 10
End If
End If
cell.EntireRow.Interior.ColorIndex = dict(cell.Value)
Next cell
Application.ScreenUpdating = True
End Sub
####
-
Sub ColorizeRowsBasedOnColumnValues()
:定义了一个名为 "ColorizeRowsBasedOnColumnValues" 的子过程(也称为宏)。