Ignoring #value in a macro

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi everyone I have a marco that colors the interior a cell depending on it's value.
Eg cell value > 65 and < 85 then vbblue
cell value > 65 then vb green
Cell value > 35 and < 65 then vbYellow
Cell value < 35 then vbRed

This works fine However is the cell has #value it's turns the cell blue?
I dont understand why?

Any ideas
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Can you paste your code?
 
Upvote 0
Dim cell as range

For each cell in range("B3:B28")
If iserror(cell.value) then
Cell.interior.colorindex =xlNone
EndIf
If cell.value > 45 then
Cell.interior.color = vbGreen
EndIf
If cell.value < 45 then
Cell.interior.color = VbRed
EndIf
Next cell
 
Upvote 0
I think you left some of the necessary code out. I do not see anything in that code setting any cells to the color blue.

If you want us to try to figure out what is going, we really need to see all of the pertinent code.
 
Upvote 0
After your set the colorindex to xlnone for errors, It still procedes to test if the cell >45, type mismatch.

You have to structure your if's in a way that it no longer tests for >45 or <45 when it's an error..

Try

Code:
Dim cell As Range
For Each cell In Range("B3:B28")
    If IsError(cell.Value) Then
        cell.Interior.ColorIndex = xlNone
    Else
        If cell.Value > 45 Then
            cell.Interior.Color = vbGreen
        End If
        If cell.Value < 45 Then
            cell.Interior.Color = vbRed
        End If
    End If
Next cell

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top