Need to highlight cell with date

MacroBB

New Member
Joined
Mar 20, 2023
Messages
12
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello all,

Can I get some help on how to use VBA to highlight cells in a daily report that have approximately 500 lines with multiple date columns? Only need to high light cells in Column B if it's equal to or later/bigger than Column A but earlier/smaller than any of the following column C to F? For example:
Date ADate B (Column need to be highlighted)Date CDate DDate EDate F
Jan 10Jan 9Jan 9
Jan 10Jan 11Jan 12Jan 12Jan 13
Jan 15Jan 15Jan 9Jan 15Jan 13
Jan 15Jan 16Jan 15Jan 16Jan 17
Feb 1Jan 31Feb 1Feb 1Feb 1

What I would like to see:
Date ADate B (Column need to be highlighted)Date CDate DDate EDate F
Jan 10Jan 9Jan 9
Jan 10Jan 11Jan 12Jan 12Jan 13
Jan 15Jan 15Jan 9Jan 15Jan 13
Jan 15Jan 16Jan 15Jan 16
Feb 1Jan 31Feb 1Feb 1Feb 1

Thanks for your help!
 
That will require a re-write, which I can do but it's the last modification so make sure you've uncovered everything.
EDIT - unclear as to what that applies to - A/B columns or the range from C to F
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Sorry, I wasn't clear with my last post.
I meant, need two different colors to highlight cells in Column B: e.g. RED if it's equal to or later/bigger than Column A but smaller than any of the following column C to F; and then GREEN if it's equal to or later/bigger than Column A and also equal to any of the following column C to F
 
Upvote 0
It wasn't as big a deal as I though it would be. Try
VBA Code:
Sub testRangeArray()
Dim ary As Variant
Dim Lrow As Long
Dim i As Integer, n As Integer, dblDate1 As Double, dblDate2 As Double
Dim blnGreater As Boolean, blnEqual As Boolean

Lrow = Cells(Rows.Count, "B").End(xlUp).Row
For i = 1 To Lrow
    blnGreater = False
    blnEqual = False
    dblDate1 = Range("A" & i)
    dblDate2 = Range("A" & i).Offset(0, 1)
    'compare col's A and B
    If dblDate1 <= dblDate2 Then
        ary = Range("C" & i & ":F" & i)
        For n = 1 To UBound(ary, 2)
            If dblDate2 < CDbl(ary(1, n)) And WorksheetFunction.IsNumber(CDbl(ary(1, n))) Then
                blnGreater = True
                Exit For
            End If
            If dblDate2 = CDbl(ary(1, n)) And WorksheetFunction.IsNumber(CDbl(ary(1, n))) Then
               blnEqual = True
               Exit For
            End If
        Next
    End If
    If blnGreater = True Then Range("A" & i).Offset(0, 1).Font.Color = vbRed
    If blnEqual = True Then Range("A" & i).Offset(0, 1).Font.Color = vbGreen
Next

End Sub
 
Upvote 1
Solution
Worked perfectly, you have been a wonderful great help!! Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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