Highlight cells based on date value

L

Legacy 477849

Guest
Hi, I'm new to VBA and would appreciate some help on this. I have a dataset as follows and would like to highlight my cells based on the following rules.
Col ACol BCol CCol D
Stage 1 (header row)Stage 1 (header row)Stage 2 (header row)Stage 2 (header row)
Target date (sub-header)Actual date (sub-header)Target date (sub-header)Actual date (sub-header)
xxxxxxxx
  • For each stage (i.e. stage 1 or 2), if the actual date is later than the target date, to highlight the cell for Actual date (col B and/or D) in red.
  • For each stage (i.e. stage 1 or 2), if the actual date is earlier than the target date, to highlight the cell for Actual date (col B and/or D) in green.
  • If there is no date input into Actual date field (i.e. Col B/D), and it is now 1 month away from the target date, to highlight as orange.
  • If target date is more than 1 month away from the current as-of date, to leave the "Actual date" cell as white.
Would truly appreciate some help on this please. Thanks!!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,

Try:

VBA Code:
Sub makeso()

Dim colnum As Long
Dim rownum As Long

rownum = 3
colnum = 1

Do Until Cells(rownum, colnum) = ""
    Do Until Cells(rownum, colnum) = ""
        If Cells(rownum, colnum) < Cells(rownum, colnum + 1) And Cells(rownum, colnum + 1) <> "" Then
            Cells(rownum, colnum + 1).Interior.Color = vbRed
        ElseIf Cells(rownum, colnum) > Cells(rownum, colnum + 1) And Cells(rownum, colnum + 1) <> "" Then
            Cells(rownum, colnum + 1).Interior.Color = vbGreen
        ElseIf Cells(rownum, colnum + 1) = "" And DateValue(Cells(rownum, colnum)) < DateAdd("m", 1, Now()) Then
            Cells(rownum, colnum + 1).Interior.Color = RGB(255, 180, 0)
        Else
            Cells(rownum, colnum + 1).Interior.Color = xlNone
        End If
    rownum = rownum + 1
    Loop
colnum = colnum + 2
rownum = 3
Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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