Use of Interior.ColorIndex

L

liquidhot

I'm attempting to color an excel spreadsheet every other row, withou
affecting cells that already have a color in them other than values 3
and 20.

However, I'm not sure I'm correctly using the ColorIndex properly an
currently my code doesn't color anything.

Can anyone see why?


Code
-------------------
Sub ColorRows()
'//This subroutine ignores cells colored something other than 37 and 20.
Dim Row As Range 'The Current row
Dim OrderRange As Range 'The Project number column
Dim Cell As Range
Dim RowCell As Range
Dim Color As Boolean 'Alternating Color
Dim CountCell As Integer 'Current project number

Set OrderRange = Range("A14", "A500")
Color = True
CountCell = 1

For Each Cell In OrderRange
If Cell.Value = CountCell Then 'see if it's in order
Set Row = Range(Cell, "EE" & Cell.Row) 'Select row out to column EE

For Each RowCell In Row
Select Case RowCell.Interior.ColorIndex
Case 37
If Color Then
RowCell.Interior.ColorIndex = 37 'Darkerblue color
Else
RowCell.Interior.ColorIndex = 20 'lighterblue color
End If
Case 20
If Color Then
RowCell.Interior.ColorIndex = 37 'Darkerblue color
Else
RowCell.Interior.ColorIndex = 20 'lighterblue color
End If
Case Else
'Do nothing
End Select
Next
If Color Then
Color = False
Else
Color = True
End If

CountCell = CountCell + 1
ElseIf Cell.Value = "" Then 'see if count should be reset
CountCell = 1
Color = True
End If
Next

Call Develop_GANTT

End Su
 
T

Tom Ogilvy

Your code worked fine for me or at least it worked as I expected it to work.
If A14 doesn't contain 1 and progress by 1 in subsequent rows, then your
code won't pass the very first test and will do nothing.
 
L

liquidhot

I just figured it out! I was using color 34 in my Excel sheet! (Which is
very close to color 20).

Fixed!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top