I inherited an Excel 2010 workbook that is utilized to import in another excel data feed that is extracted from online source daily. Once imported this .xlsm workbook does several things, custom columns, several sorts, conditional formatting, etc. It currently highlights all rows that have a CreatedDate of the current date. I need to modify this to evaluated the CreatedDate and highlight all rows in the last 24 hours as opposed to just the current date. I am struggling to find where I need to modify this code which is listed below. Additionally, to address a sorting problem, the initial creator of this strips the time of the CreateDate field upon import. The code below refers to the specific section of the macro that performs the highlighting of rows..
Code:
Public Sub highlightFields()
Dim finalrow, finalcol, x As Long
Dim cd, election, elec_dd, proj_type As String
finalcol = Cells.Find("*", searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
finalrow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For x = 1 To finalcol
Select Case Trim(Cells(2, x).Text)
Case "Election Due Date"
elec_dd = MyColumnLetter(x * 1)
Case "Created Date"
cd = MyColumnLetter(x * 1)
Case "Election"
election = MyColumnLetter(x * 1)
Case "Project Type"
proj_type = MyColumnLetter(x * 1)
End Select
Next
For x = 3 To finalrow
If DateDiff("d", Date, Range(elec_dd & x).Value) <= 7 Then
With Range(elec_dd & x).Font
.Bold = True
.Color = -16776961
.TintAndShade = 0
End With
End If
If CStr(Range(cd & x).Value) = CStr(Date) Then
If Trim(Range(election & x).Value) <> "" Then
With Range(election & x).Font
.Bold = True
.Color = -16776961
.TintAndShade = 0
End With
End If
With Range("A" & x & ":" & MyColumnLetter(finalcol * 1) & x).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
End If
If Range(proj_type & x) = "Initial Well" Then
With Range(elec_dd & x).Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
End If
Next
End Sub