VBA Format Cell in range if its a Date and greater than row 9.

Trebor200

Board Regular
Joined
Apr 21, 2015
Messages
67
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have range starting at K9 that can extend down many rows and across many columns.

I would like an if statement to check if first its a date and then if the date itself is less than today or greater than the date in the same column on row 9 turn red.. example below..

Hoping someone could help... thanks.

Date_Format Example.2.JPG
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
 
Upvote 0
TestFormat for X-Chart.xlsm
ABCDEFGHIJKLMNOPQRS
1
2
3
4
5
6
7
8
9Start25/03/202125/03/202103/09/202110/09/202117/09/202124/09/202101/10/202108/10/202115/10/2021
10
1107/05/202107/05/202124/05/202124/05/202117/09/202117/09/202117/09/202117/09/202117/09/2021
12xx11/05/202103/09/202103/09/202103/09/202103/09/202103/09/202118/10/2021
13xx03/09/202110/09/202110/09/202110/09/202110/09/202108/10/202115/10/2021
14xxs21/09/202121/09/202121/09/202121/09/202121/09/202121/09/2021
15xxss21/09/202121/09/202121/09/202121/09/202121/09/2021
16xxsssss06/09/202106/09/2021
17xx03/09/202110/09/202117/09/202124/09/202101/10/202108/10/202115/10/2021
18xx15/07/202115/07/202117/09/202117/09/202117/09/202117/09/202117/09/2021
19xx03/09/202110/09/202117/09/202124/09/202101/10/202108/10/202115/10/2021
20xx20/08/202120/08/202116/09/202116/09/202116/09/202117/09/202117/09/2021
21xx06/09/202106/09/202106/09/202124/09/202124/09/202124/09/202124/09/2021
22xx03/09/202110/09/202117/09/202124/09/202101/10/202108/10/202115/10/2021
23xxsssssss
24xxsssssss
25xx05/08/202105/08/202105/08/202105/08/202105/08/202105/08/202105/08/2021
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
L11Cell Value>L$9textNO
M25:S25Cell Value>M$9textNO
M17:Q22Cell Value>M$9textNO
R16:S22Cell Value>R$9textNO
O15:S15Cell Value>O$9textNO
M11:S11Cell Value>M$9textNO
N14:S14Cell Value>N$9textNO
K11Cell Value>K$9textNO
M12:S13Cell Value>M$9textNO
 
Upvote 0
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
Hi Thanks for reply i have added i have manually used conditional format to show example.
 
Upvote 0
VBA Code:
Option Explicit

Sub Foo()
    Dim rng As Range
    Dim c As Range
    Dim lc As Long, lr As Long, cCol As Long
    lc = Cells(9, Columns.Count).End(xlToLeft).Column
    lr = Range("K" & Rows.Count).End(xlUp).Row
    Set rng = Range(Cells(9, 11), Cells(lr, lc))
    For Each c In rng
        If IsDate(c) Then
            cCol = c.Column
            If c > Cells(9, cCol) Then
                c.Interior.ColorIndex = 38
                c.Font.ColorIndex = 3
            End If
        End If
    Next c
    MsgBox "completed"

End Sub
 
Upvote 0
VBA Code:
Option Explicit

Sub Foo()
    Dim rng As Range
    Dim c As Range
    Dim lc As Long, lr As Long, cCol As Long
    lc = Cells(9, Columns.Count).End(xlToLeft).Column
    lr = Range("K" & Rows.Count).End(xlUp).Row
    Set rng = Range(Cells(9, 11), Cells(lr, lc))
    For Each c In rng
        If IsDate(c) Then
            cCol = c.Column
            If c > Cells(9, cCol) Then
                c.Interior.ColorIndex = 38
                c.Font.ColorIndex = 3
            End If
        End If
    Next c
    MsgBox "completed"

End Sub
Excellent worked a treat Thank You
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,038
Latest member
apwr

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