Rows ColorIndex

  • Thread starter Thread starter CG Rosén
  • Start date Start date
C

CG Rosén

Hi Group,

Needs some help on following;
Have a column with variable values as:
1
1
1
2
2
3
4
4
4
5
5
etc
The number of rows with 1:s etc are changing. Try to give the rows with the
same value the same InteriorColor in 2 shades.
First all 1:s to be ColorIndex =15 then the 2:s Colorindex = 0 then again
the 3:s ColorIndex = 15 etc.
What is the best approch to this ?

Happy New Year

CG Rosén
 
Sub Tester1()
Dim icolor As Long
Dim i As Long
Dim rng As Range
icolor = 0
Set rng = Cells(1, 1)
i = 1
Do While Not IsEmpty(Cells(i, 1))
If Cells(i + 1, 1) <> Cells(i, 1) Then
If icolor = 0 Then icolor = 15 Else icolor = 0
Range(rng, Cells(i, 1)).Interior.ColorIndex = icolor
Set rng = Cells(i + 1, 1)
End If
i = i + 1
Loop

End Sub
 
Back
Top