我有一些脚本用于着色具有重复值(多种颜色)的单元格:
Sub DuplicateColoring()
On Error Resume Next
' colors to change cells color
Colors = Array(12900829, 15849925, 14408946, 14610923, 15986394, 14281213, 14277081, _
9944516, 14994616, 12040422, 12379352, 15921906, 14336204, 15261367, 14281213)
Dim coll As New Collection, dupes As New Collection, _
cols As New Collection, ra As Range, cell As Range, n&
Err.Clear: Set ra = Intersect(Selection, ActiveSheet.UsedRange)
If Err Then Exit Sub
ra.Interior.ColorIndex = xlColorIndexNone: Application.ScreenUpdating = False
For Each cell In ra.Cells ' remember duplicates values in dupes
Err.Clear: If Len(Trim(cell)) Then coll.Add CStr(cell.Value), CStr(cell.Value)
If Err Then dupes.Add CStr(cell.Value), CStr(cell.Value)
Next cell
For i& = 1 To dupes.Count ' fill cols with colors for different duplicates
n = n Mod (UBound(Colors) + 1): cols.Add Colors(n), dupes(i): n = n + 1
Next
For Each cell In ra.Cells ' coloring cells
cell.Interior.color = cols(CStr(cell.Value))
Next cell
Application.ScreenUpdating = True
End Sub
我希望这个脚本不仅可以为单元格着色,还可以为整行着色。我怎么能这样做?
答案 0 :(得分:0)
替换
cell.Interior.color = cols(CStr(cell.Value))
带
cell.EntireRow.Interior.color = cols(CStr(cell.Value))