toshimarise
New Member
- Joined
- Feb 1, 2013
- Messages
- 21
This macro is pretty repetitive, sorry about that. It colors cells in two columns based on certain conditions. There are two columns (RangeToday and RangeYesterday). The operations are repeated on two tabs (Employees and Contractors).
Most of it works fine, but one of the color-change conditions that appears on both tabs does not always work (marked by a comment in the code). In the RangeYesterdayEOD on the Employees tab, the IsError condition doesn't turn any cells grey, even if they contain an error. All the other conditions are working fine in all four columns. Also the IsError condition works fine in the other 3 columns.
Any help is much appreciated!
Code:
Sub Coloring()
' color codes apparent delinquencies for today and yesterday EOD
' checks for 0s, specific error codes ( U and L), comments, blanks, and error values
Dim LastCol As Long
Dim LastRow As Long
Sheets("Contractors").Activate
With ActiveSheet
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
' Last column (Today)
Dim Cell As Range
Set RangeToday = Range(Cells(2, LastCol), Cells(LastRow, LastCol))
For Each Cell In RangeToday.Cells
' Color 0s red
If Not IsError(Cell) Then
If Cell.Value = "0" Then
Cell.Interior.Color = RGB(220, 0, 0)
Cell.Font.Bold = True
End If
End If
'color errors grey
If IsError(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color blanks grey
If IsEmpty(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color comments yellow
If Not Cell.Comment Is Nothing Then
Cell.Interior.ColorIndex = 27
End If
Next
' 2nd to last column (Yesterday EOD)
Set RangeYesterdayEOD = Range(Cells(2, LastCol - 1), Cells(LastRow, LastCol - 1))
For Each Cell In RangeYesterdayEOD.Cells
If Not IsError(Cell) Then
'color Ls red
If Cell.Value Like "*L*" Then
Cell.Interior.Color = RGB(220, 0, 0)
Cell.Font.Bold = True
End If
'color Us red
If Cell.Value Like "*U*" Then
Cell.Interior.Color = RGB(220, 0, 0)
Cell.Font.Bold = True
End If
'color errors grey
If IsError(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color blanks grey
If IsEmpty(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color comments yellow
If Not Cell.Comment Is Nothing Then
Cell.Interior.ColorIndex = 27
End If
End If
Next
End With
' Employees sheet
Sheets("Employees").Activate
With ActiveSheet
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
' Last column (Today)
Set RangeToday = Range(Cells(2, LastCol), Cells(LastRow, LastCol))
For Each Cell In RangeToday.Cells
' Color 0s red
If Not IsError(Cell) Then
If Cell.Value = "0" Then
Cell.Interior.Color = RGB(220, 0, 0)
Cell.Font.Bold = True
End If
End If
'color errors grey
If IsError(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color blanks grey
If IsEmpty(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color comments yellow
If Not Cell.Comment Is Nothing Then
Cell.Interior.ColorIndex = 27
End If
Next
' 2nd to last column (Yesterday EOD)
Set RangeYesterdayEOD = Range(Cells(2, LastCol - 1), Cells(LastRow, LastCol - 1))
For Each Cell In RangeYesterdayEOD.Cells
If Not IsError(Cell) Then
'color Ls red
If Cell.Value Like "*L*" Then
Cell.Interior.Color = RGB(220, 0, 0)
Cell.Font.Bold = True
End If
'color Us red
If Cell.Value Like "*U*" Then
Cell.Interior.Color = RGB(220, 0, 0)
Cell.Font.Bold = True
End If
'color errors grey
' THIS IS THE ONLY ONE NOT WORKING
If IsError(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color blanks grey
If IsEmpty(Cell) Then
Cell.Interior.Color = RGB(200, 200, 200)
End If
' color comments yellow
If Not Cell.Comment Is Nothing Then
Cell.Interior.ColorIndex = 27
End If
End If
Next
End With
End Sub
Most of it works fine, but one of the color-change conditions that appears on both tabs does not always work (marked by a comment in the code). In the RangeYesterdayEOD on the Employees tab, the IsError condition doesn't turn any cells grey, even if they contain an error. All the other conditions are working fine in all four columns. Also the IsError condition works fine in the other 3 columns.
Any help is much appreciated!