colore cell based on condition

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi everybody,
It is possible to change the color index of a cell with error 2015 (#VALUE!)?
if I get this error-cells colored with orange, then I can check the values
of the rest, somehow is stopping on the ones with errors. All cells I'm
checking are colored yellow, I'm ignoring the rest.

Thanks for any help

sub CheckValue ()

For Each c In Range("E17", "CE44")
If c.Interior.ColorIndex = 6 And _
c.Value = CVErr(xlErrValue) Then
c.Interior.ColorIndex = 44

ElseIf c.Interior.ColorIndex = 6 And _
c.Value > 9999 Then
c.Interior.ColorIndex = 44
c.FormatNumber = "0.00"
End If
Next



End Sub

gaba :)
 
Gaba,

Your problem is evaluating for an eror when there is not one there. Try
this

On Error Resume Next
For Each c In Range("E17", "CE44")
If c.Interior.ColorIndex = 6 Then
If c.Value = CVErr(xlErrValue) Then
If Err.Number = 0 Then
c.Interior.ColorIndex = 44
End If
ElseIf c.Interior.ColorIndex = 6 And _
c.Value > 9999 Then
c.Interior.ColorIndex = 44
c.FormatNumber = "0.00"
End If
End If
Next
--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bob, thanks for your answer. I've tried the code and is not catching the
numbers bigger than 9999... Soon as the value is an error quits. Any ideas?
Gaba
 
Gaba,

Is this better?

On Error Resume Next
For Each c In Range("E17", "CE44")
If c.Interior.ColorIndex = 6 Then
If c.Value = CVErr(xlErrValue) Then
If Err.Number = 0 Then
c.Interior.ColorIndex = 44
ElseIf c.Interior.ColorIndex = 6 And _
c.Value > 9999 Then
c.Interior.ColorIndex = 44
c.FormatNumber = "0.00"
End If
Err.Clear
End If
End If
Next

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks so much, Bob. It works great!

Bob Phillips said:
Gaba,

Is this better?

On Error Resume Next
For Each c In Range("E17", "CE44")
If c.Interior.ColorIndex = 6 Then
If c.Value = CVErr(xlErrValue) Then
If Err.Number = 0 Then
c.Interior.ColorIndex = 44
ElseIf c.Interior.ColorIndex = 6 And _
c.Value > 9999 Then
c.Interior.ColorIndex = 44
c.FormatNumber = "0.00"
End If
Err.Clear
End If
End If
Next

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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

Back
Top