Colour font or background if cells =

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
451
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I've tried using condtional formatting but as you know it only gives us 3 conditions. I just need anything in cells A1 to I500 to turn red if any of the following is NOT in the cell:

3:45
7:30
11:15
15:00

So basically, if any of the cells DO NOT include the above, turn the cell red.

Many thanks
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this out.

Sub col()
Dim cell As Range
For Each cell In Range("A1:I500")
If cell.Value <> 3:45 Or cell.Value <> 7:30 Or cell.Value <> 11:15 Or cell.Value <> 15:00 Then
cell.Interior.Color = vbRed
End If
Next
End Sub
 
Upvote 0
if the cell properties are in Time then you can use this marco

Code:
Sub Color_Cells()
'
For Each bCell In Range("A1:I500")

    If bCell <> TimeSerial(3, 45, 0) And bCell <> TimeSerial(7, 30, 0) And bCell <> TimeSerial(11, 15, 0) And bCell <> TimeSerial(15, 0, 0) Then
    'MsgBox bCell.Address
    Range(bCell.Address).Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    Else
    
    End If
    Next bCell

End Sub
 
Upvote 0
Thanks guys, it doesnt seem to work for some reason. Am I missing something from the code?
 
Upvote 0
Do you have conditional formatting applied? If so remove it.
 
Upvote 0
Conditional Formatting worked for me, with the formula

=ISERROR(FIND(TEXT(C1,"h:mm")&"~", "3:45~7:30~11:15~15:00~"))
 
Upvote 0
Conditional Formatting worked for me, with the formula

=ISERROR(FIND(TEXT(C1,"h:mm")&"~", "3:45~7:30~11:15~15:00~"))
That formula will fail for entries of 1:15 and 5:00. This modification to your formula should do the job though...

=ISERROR(FIND("~"&TEXT(C1,"h:mm")&"~", "~3:45~7:30~11:15~15:00~"))
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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