VBA to look at a date in A1 and then change font color of any Table1 dates that are < A1

jase71ds

Board Regular
Joined
Oct 23, 2006
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hoping someone will help me with this...

A1 = a user defined date (mm/dd/yy)
Table1 = a defined table range in which the values are either blank, or are dates (mm/dd/yy)

I need VBA to consider the date that is A1, and then look through Table1 and change the font color to red, of any cell in Table1 that contains a date that is less than the date in A1.

In other words: Within Table1, change a cell's font color to red if the date in that cell is < the date in A1.
(Note: A1 and Table1 are on the same worksheet page)

Normally I would use conditional formatting - but for reasons too long to discuss, I need to avoid CF.

Thanks for any help. As always, it is greatly appreciated.

Jase.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
try this.

Code:
Sub Format_it()


For Each cell In Range("Table1")
If cell < [A1] And IsDate(cell) = True Then


With cell.Font
        .Color = -16776961
        .TintAndShade = 0
End With
    
Else
With cell.Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
End With

End If

Next cell

End Sub

hth,

Ross
 
Upvote 0
Ah! Thank you, thank you, thank you!!
Your code taught me what I was doing incorrectly!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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