Highlighting Passed Date and Another Cell is Blank

Darlie247

New Member
Joined
Apr 2, 2022
Messages
13
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I know I can accomplish this using conditional formatting; however, there is/will be a lot of data so I wanted a VBA to do this.

What I am wanting to do is have the "PO# Due Date" in Column Q highlight red if it is past Today and Column W ("Received Date") is blank, and/or Column W is passed the date in Column Q. Does this make any sense?

Thanks ahead for any help or advice!


Ordering - Copy.xlsm
PQSTUVW
1
2
3
4PO#PO# DUE DATE RECEIVED QUANTITY RECEIVED UNIT RECEIVED UNIT AMOUNT RECEIVING TECH RECEIVED DATE
5124-Mar-2220Vial-
6224-Mar-2230Bottle-DAF
7324-Mar-226Each-DAF
8424-Mar-226Each-DAF
2022
Cells with Data Validation
CellAllowCriteria
T5:T8ListEach, Bag of, Bottle, Box, Box of, Case of, Kit, Milliliter, Ounce, Pad of, Package of, Roll, Roll of, Sheet, Vial
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Does this give you what you want?

Darlie247.xlsx
PQSTUVW
1
2
3
4PO#PO# DUE DATE RECEIVED QUANTITY RECEIVED UNIT RECEIVED UNIT AMOUNT RECEIVING TECH RECEIVED DATE
5105-Apr-2220Vial-
6224-Mar-2230Bottle-DAF04-Apr-22
7305-Apr-226Each-DAF05-Apr-22
8424-Mar-226Each-DAF06-Apr-22
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
Q5:Q8Expression=OR(AND(Q5>TODAY(),W5=""),W5>Q5)textNO
 
Upvote 0
Does this give you what you want?

Darlie247.xlsx
PQSTUVW
1
2
3
4PO#PO# DUE DATE RECEIVED QUANTITY RECEIVED UNIT RECEIVED UNIT AMOUNT RECEIVING TECH RECEIVED DATE
5105-Apr-2220Vial-
6224-Mar-2230Bottle-DAF04-Apr-22
7305-Apr-226Each-DAF05-Apr-22
8424-Mar-226Each-DAF06-Apr-22
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
Q5:Q8Expression=OR(AND(Q5>TODAY(),W5=""),W5>Q5)textNO
This is great! But would this slow down the workbook if I did this conditional formatting down the entire column of Q? Or is it simple/basic enough that excel could handle it?

Thanks for your help!! :)
 
Upvote 0
Is it possible for a VBA to do this as well? I'm worried that conditional formatting might slow this workbook down...
 
Upvote 0
Is it possible for a VBA to do this as well? I'm worried that conditional formatting might slow this workbook down...
I think you're right - I personally would also go for a VBA approach. There are 2 options

1. Run the macro yourself (put the following code in a standard module)
VBA Code:
Option Explicit
Sub Darlie247()
    Dim rng As Range, c As Range
    Application.ScreenUpdating = False
    Set rng = Range("Q5:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
        For Each c In rng
            If (c.Value > Date And c.Offset(, 6) = "") Or (c.Offset(, 6) > c.Value) Then
                c.Font.Color = vbRed
                Else
                c.Font.ColorIndex = xlAutomatic
            End If
        Next c
    Application.ScreenUpdating = True
End Sub

2. Have the code run automatically whenever there's a change in columns Q or W (put the following code in the code area of the sheet)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("Q:Q,W:W"), Target) Is Nothing Then
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        Dim rng As Range, c As Range
        Set rng = Range("Q5:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
        For Each c In rng
            If (c.Value > Date And c.Offset(, 6) = "") Or (c.Offset(, 6) > c.Value) Then
                c.Font.Color = vbRed
                Else
                c.Font.ColorIndex = xlAutomatic
            End If
        Next c
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End If
End Sub
 
Upvote 0
Solution
I think you're right - I personally would also go for a VBA approach. There are 2 options

1. Run the macro yourself (put the following code in a standard module)
VBA Code:
Option Explicit
Sub Darlie247()
    Dim rng As Range, c As Range
    Application.ScreenUpdating = False
    Set rng = Range("Q5:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
        For Each c In rng
            If (c.Value > Date And c.Offset(, 6) = "") Or (c.Offset(, 6) > c.Value) Then
                c.Font.Color = vbRed
                Else
                c.Font.ColorIndex = xlAutomatic
            End If
        Next c
    Application.ScreenUpdating = True
End Sub

2. Have the code run automatically whenever there's a change in columns Q or W (put the following code in the code area of the sheet)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("Q:Q,W:W"), Target) Is Nothing Then
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        Dim rng As Range, c As Range
        Set rng = Range("Q5:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
        For Each c In rng
            If (c.Value > Date And c.Offset(, 6) = "") Or (c.Offset(, 6) > c.Value) Then
                c.Font.Color = vbRed
                Else
                c.Font.ColorIndex = xlAutomatic
            End If
        Next c
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End If
End Sub
Thanks so much! Both of these work great! :)
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,619
Members
449,238
Latest member
wcbyers

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