I have this snippet of code that will highlight select rows of data within a table different colors based on varying parameters:
Public Sub HighlightRecentSampleRequests()
Dim sht As Worksheet
Dim LastRow As Long
Dim cell As Range
Dim dt, txt
Set sht = Worksheets("Sample Transfer Log")
LastRow = sht.Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In sht.Range("K3:K" & LastRow).Cells
dt = cell.Value
txt = cell.Offset(0, -3).Value
If dt >= Date - 7 And txt = "Sample Receipt" Then
cell.Range("A1:P1").Offset(0, -10).Interior.ColorIndex = 45 'orange
ElseIf dt >= Date Then
cell.Range("A1:P1").Offset(0, -10).Interior.ColorIndex = 6 'yellow
Else
cell.Range("A1:P1").Offset(0, -10).Interior.Color = RGB(220, 230, 242) 'default color
End If
Next
End Sub
I made an alteration to my original code to produce the above to make it do what I wanted. Now I am receiving the 'Out of Memory' message constantly when I run my system. This seems to be due to the last portion of the If statement where all cells that do not meet the previous criteria will be highlighted as the default color. I attempted to refer to the range using a variable and then setting that variable to 'Nothing' after completing its use, but that returned a message of 'Invalid Use of Null' and thereafter those variables were useless and needed to be deleted for the code to work again.
Basically, I would like to get rid of the 'Out of Memory' message without screwing up my entire code.