AW: Nach gleiche Zellen suchen und einfärben
01.06.2006 18:15:54
Franz
Hallo Kay,
habe deinen Code mal etwas umgestrickt. :-)
Sub colourieren()
Dim iRow1 As Long, iRow2 As Long, iRowL As Long
Dim col As Integer
Dim col2 As Integer
Dim col3 As Integer
Dim icolor as Integer
Dim SpalteA() As Boolean
iRowL = WorksheetFunction.CountA(Columns(1))
ReDim SpalteA(1 To iRowL)
icolor = 2
For iRow1 = 1 To iRowL
If Not SpalteA(iRow1) = True Then 'prüft ob Zeile bereits coloriert wurde
SpalteA(iRow1) = True
col = Int((255 - 0 + 1) * Rnd + 0)
col2 = Int((255 - 0 + 1) * Rnd + 0)
col3 = Int((255 - 0 + 1) * Rnd + 0)
Rows(iRow1).Interior.ColorIndex = icolor
' Rows(iRow1).Interior.Color = RGB(col, col2, col3)
For iRow2 = iRow1 + 1 To iRowL
If Cells(iRow1, 1).Value = Cells(iRow2, 1) Then
SpalteA(iRow2) = True
If Cells(iRow1, 1).Value = "KW" Then
Cells(iRow1, 1).EntireRow.Interior.ColorIndex = 0
Cells(iRow1, 1).EntireRow.Font.Bold = True
Else
Rows(iRow2).Interior.ColorIndex = icolor
' Rows(iRow2).Interior.Color = RGB(col, col2, col3)
End If
End If
Next iRow2
icolor = icolor + 1
If icolor = 40 Then icolor = 2
End If
Next iRow1
Range("A1").Select
End Sub
Du kannst dir ja noch einrichten, ob du die Farben per Zufallsgenerator als RGB wählst oder mit dem Colorindex arbeiten willst. Ich halte den Colorindex für günstiger als RGB, da sich das Farbschema nicht bei jedem Makrodurchlauf ändert. Und die ca. 40 Farben, die Colorindex ermöglicht sind ja auch schon ganz schön bunt.
Gruß
Franz