Cell wont change colour

E

evil baby

I'm pretty sure it has something to do with my end if but I'm not really
used to excel programming.

Range("G24").Select
Do While ActiveCell <> 0
x = ActiveCell.Offset(-1, 0).Value
If ActiveCell.Value >= (x - (x * 0.06)) Then
If ActiveCell.Value <= (x + (x * 0.06)) Then
ActiveCell.Interior.ColorIndex = 35
ActiveCell.Font.ColorIndex = 1
End If
'HERE IS WHERE THE PROBLEM IS - it wont recognize the next elseif
statment. I just skips it. Everything else works fine, just not this
statement

'***********************************************
ElseIf ActiveCell.Value > (x + (x * 0.06)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2

'***********************************************
ElseIf ActiveCell.Value < (x - (x * 0.11)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
Else
ActiveCell.Interior.ColorIndex = 36
ActiveCell.Font.ColorIndex = 1
End If
ActiveCell.Offset(0, 1).Select
Loop
 
T

Tom Ogilvy

Range("G24").Select
Do While ActiveCell <> 0
x = ActiveCell.Offset(-1, 0).Value
If ActiveCell.Value >= (x - (x * 0.06)) or _
ActiveCell.Value <= (x + (x * 0.06)) Then
ActiveCell.Interior.ColorIndex = 35
ActiveCell.Font.ColorIndex = 1
ElseIf ActiveCell.Value > (x + (x * 0.06)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
ElseIf ActiveCell.Value < (x - (x * 0.11)) Then
ActiveCell.Interior.ColorIndex = 3
ActiveCell.Font.ColorIndex = 2
Else
ActiveCell.Interior.ColorIndex = 36
ActiveCell.Font.ColorIndex = 1
End If
ActiveCell.Offset(0, 1).Select
Loop
 
E

evil baby

Thanks again for the help, wasn't sure how logical and/or worked in
VBA.

I had to change your 'Or' to an 'And' but it worked like a charm after
that.
 

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