colour cell if the equation is zero

white_flag

Active Member
Joined
Mar 17, 2010
Messages
331
Hello:

I have an range that will return zero values but like this =B26*G45 not luike an value (zero) the calculation will be zero. Can some one give mean code that if the result of the cell is zero then the cell to become in an different color.

I found this code on this site:

Code:
Function HasZerosOnly(ByVal Target As Range) As Boolean
    Dim c As Range
    For Each c In Target
        If Not c.Value = 0 Then Exit Function
    Next
    HasZerosOnly = True
End Function

Code:
'this is inside of the sub
If HasZerosOnly(my_range) Then my_range.Cells.Interior.Color = 36
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
p45cal, thx for the sugestion. I putted like this:


Code:
Dim Cell As Range
    
On Error Resume Next
For Each Cell In my_range
   Select Case Cell.Value
        Case vbNullString
            Cell.Interior.ColorIndex = xlNone
            Cell.Font.Bold = False
        Case "0"
            Cell.Interior.ColorIndex = 1
            Cell.Font.Bold = False
    End Select
Next
 
Upvote 0
p45cal, thx for sugestion. I putted like this:

Code:
Dim Cell As Range
    
On Error Resume Next
For Each Cell In my_range
   Select Case Cell.Value
        Case vbNullString
            Cell.Interior.ColorIndex = xlNone
            Cell.Font.Bold = False
        Case "0"
            Cell.Interior.ColorIndex = 1
            Cell.Font.Bold = False
    End Select
Next
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

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