A
A
Alexander Lebedev2014-06-11 01:18:52
Macros
Alexander Lebedev, 2014-06-11 01:18:52

Changing row color in Excel via VBA script/macro?

Good afternoon.
I have a script to color cells with duplicates in different colors:

Sub ВыделитьДубликатыРазнымиЦветами()
    On Error Resume Next
    ' массив цветов, используемых для заливки ячеек-дубликатов
   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 ' запонимаем значение дубликатов в коллекции 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 ' заполняем коллекцию cols цветами для разных дубликатов
       n = n Mod (UBound(Colors) + 1): cols.Add Colors(n), dupes(i): n = n + 1
    Next
    For Each cell In ra.Cells ' окрашиваем ячейки, если для её значения назначен цвет
       cell.Interior.color = cols(CStr(cell.Value))
    Next cell
    Application.ScreenUpdating = True
End Sub

How can I make this code color not only the cell, but the entire row? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lebedev, 2014-06-11
@sortarage

Everything, sorry, figured it out myself, replaced it
with

cell.EntireRow.Interior.color = cols(CStr(cell.Value))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question