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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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