Change Cell Color Based on Color Index and Value

TheCastillian

New Member
Joined
May 18, 2016
Messages
2
Hi all,

I could use a hand with this one.

I have tested this on a single cell and it works great, however, I want to apply this to an entire sheet. ie Range(A1:BP65). With that said, A1 on the code is set as Today() and the intent is to run the code to determine what cells are passed due. I want to identify if any of the cells in the range are passed due and are not green (46).

Sub CellColor()
'This formula will change the color of cell that is passed due and not complete
'Color 43 is the green color that is used to signify that a job is complete
'Color 6 is yellow and will signify that a task is late
If Range("A2") < Range("A1") Then
If Range("A2").Interior.ColorIndex <> 43 Then
Range("A2").Interior.ColorIndex = 6
End If
End If
End Sub

Thanks in advance...
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I'm confused by the layout of your worksheet, but this may point you in the right direction

starting with:

Excel 2010
ABCDE
15/19/2016
25/15/20165/20/20165/16/20165/18/20165/16/2016
35/19/20165/18/20165/20/20165/19/20165/16/2016
45/18/20165/20/20165/21/20165/16/20165/15/2016
55/17/20165/16/20165/19/20165/17/20165/20/2016
65/15/20165/15/20165/20/20165/19/20165/15/2016
Sheet1
Cell Formulas
RangeFormula
A1=TODAY()

Run this:
Code:
Sub CellColor2()Dim iDone As Integer
Dim iLate As Integer
Dim dtDUE As Date
Dim cel As Range
Dim rng As Range


iDone = 43      'green
iLate = 6       'yellow
Set rng = Range("A2:E6")
dtDUE = Range("A1").Value


For Each cel In rng
    If cel < dtDUE Then
        With cel.Interior
            If Not .ColorIndex = iDone Then .ColorIndex = iLate
        End With
    End If
Next cel


End Sub

Gives you this:

Excel 2010
ABCDE
15/19/2016
25/15/20165/20/20165/16/20165/18/20165/16/2016
35/19/20165/18/20165/20/20165/19/20165/16/2016
45/18/20165/20/20165/21/20165/16/20165/15/2016
55/17/20165/16/20165/19/20165/17/20165/20/2016
65/15/20165/15/20165/20/20165/19/20165/15/2016
Sheet1
Cell Formulas
RangeFormula
A1=TODAY()
 
Upvote 0
CalcSux- that is EXACTLY what I needed. you are the man. This works perfect, I guess I was chasing my tail.

Thank you for your time on this!!!!
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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