【发布时间】:2014-06-11 08:35:19
【问题描述】:
我有一些脚本用于为具有重复值(多种颜色)的单元格着色:
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
我希望这个脚本不仅为单元格着色,而且为整行着色。我该怎么做?
【问题讨论】:
-
将 cell.Interior.color = cols(CStr(cell.Value)) 替换为 cell.EntireRow.Interior.color = cols(CStr(cell.Value))?
-
已将其作为答案发布,请接受它以便将问题标记为已回答
-
怎么做?只是“谢谢”,还是某个按钮?对不起,我是新手。
-
或者,我明白了。标记它。一切都好?再次感谢)