Thread: ElseIf
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
tom1646 tom1646 is offline
external usenet poster
 
Posts: 6
Default ElseIf

sorted it now, thanks frank it was that i needed to use xlnone rather than 0
in the if statement.

"tom1646" wrote:

Thanks for your help. I have included all of the if statement, i warn you
now it is messy! I understood colorindex = 0 to mean 'no color' I have used
this before and it seems to have worked fine.

Thanks......

Set rg = Range("c3:z3")

For i = 1 To rg.Cells.Count

If rg2(i).Interior.color = RGB(0, 255, 0) And rg3(i).Interior.color =
RGB(0, 255, 0) And rg4(i).Interior.color = RGB(0, 255, 0) Then
rg(i).Interior.color = RGB(0, 255, 0)

ElseIf rg2(i).Interior.color = RGB(255, 255, 0) And
rg3(i).Interior.color = RGB(0, 255, 0) And rg4(i).Interior.color = RGB(0,
255, 0) Then
rg(i).Interior.color = RGB(0, 255, 0)


ElseIf rg2(i).Interior.color = RGB(0, 255, 0) And
rg3(i).Interior.color = RGB(255, 255, 0) And rg4(i).Interior.color = RGB(0,
255, 0) Then rg(i).Interior.color = RGB(0, 255, 0)

ElseIf rg2(i).Interior.color = RGB(0, 255, 0) And
rg3(i).Interior.color = RGB(0, 255, 0) And rg4(i).Interior.color = RGB(255,
255, 0) Then rg(i).Interior.color = RGB(0, 255, 0)

ElseIf rg2(i).Interior.color = RGB(255, 0, 0) And
rg3(i).Interior.color = RGB(255, 0, 0) And rg4(i).Interior.color = RGB(255,
0, 0) Then rg(i).Interior.color = RGB(255, 0, 0)

ElseIf rg2(i).Interior.color = RGB(255, 0, 0) And
rg3(i).Interior.color = RGB(255, 0, 0) And rg4(i).Interior.color = RGB(255,
255, 0) Then rg(i).Interior.color = RGB(255, 0, 0)

ElseIf rg2(i).Interior.color = RGB(255, 0, 0) And
rg3(i).Interior.color = RGB(255, 255, 0) And rg4(i).Interior.color = RGB(255,
0, 0) Then rg(ie).Interior.color = RGB(255, 0, 0)

ElseIf rg2(i).Interior.color = RGB(255, 255, 0) And
rg3(i).Interior.color = RGB(255, 0, 0) And rg4(i).Interior.color = RGB(255,
0, 0) Then rg(i).Interior.color = RGB(255, 0, 0)

ElseIf ((rg2(i).Interior.ColorIndex = 0) Or
(rg3(i).Interior.ColorIndex = 0) Or (rg4(i).Interior.ColorIndex = 0)) Then
rg(i).Interior.ColorIndex = "0"

Else
rg(i).Interior.color = RGB(255, 255, 0)
End If

Next i


"K Dales" wrote:

Would help to see the rest of your IF statement, but it is probably from the
ambiguity of the ORs you combine together. As an illustration: I am sure you
mean (a=b) or (c=d) or (e=f), but I could also read that as a=(b or (c=d)) or
(e=f): so the order in which you do the =s and ors makes a big difference.
It is my practice to always use parentheses to force the order of logical
tests the way I intend it - this is often "unnecessary" but I think it is
good programming practice and makes for more readable code.

So try this:
ElseIf ((rg2(i).Interior.ColorIndex = 0) Or (rg3(i).Interior.ColorIndex = 0)
Or
(rg4(i).Interior.ColorIndex = 0)) Then...

K Dales