So I've been trying to solve this problem for a while now... a few weeks. I'm trying to get this code to run down a column and fill the row in a certain color (not the entire row though, just the cells with text in them - if there is a better way to do it that would be great to know also!
) and STOP WHEN IT GETS TO A BLANK CELL!!!
This seems to be a common theme, but I can't get the code from any of the other postings to work. No matter what I try, I just can't get it to stop! A bright and shiney gold star to anyone who can help...
Here is my code:
Sub Metrics()
'Set MyCell as the range
Dim MyCell As Range
x = 2
Columns("F:F").Select
Do While Cells(x, 6).Value <> ""
'Loop using a For Each…Next in selection
For Each MyCell In Selection
If MyCell.Value = "" Then
'Clear the cell background color
MyCell.Interior.ColorIndex = xlNone
ElseIf MyCell.Value Like "*Go to*" Then
'Set the cell background color to dark orange
MyCell.Interior.ColorIndex = 46
MyCell.Offset(0, -5).Interior.ColorIndex = 46
MyCell.Offset(0, -4).Interior.ColorIndex = 46
MyCell.Offset(0, -3).Interior.ColorIndex = 46
MyCell.Offset(0, -2).Interior.ColorIndex = 46
MyCell.Offset(0, -1).Interior.ColorIndex = 46
MyCell.Offset(0, 1).Interior.ColorIndex = 46
ElseIf MyCell.Value Like "*Merged as child*" Then
'Set the cell background color to light yellow
MyCell.Interior.ColorIndex = 36
MyCell.Offset(0, -5).Interior.ColorIndex = 36
MyCell.Offset(0, -4).Interior.ColorIndex = 36
MyCell.Offset(0, -3).Interior.ColorIndex = 36
MyCell.Offset(0, -2).Interior.ColorIndex = 36
MyCell.Offset(0, -1).Interior.ColorIndex = 36
MyCell.Offset(0, 1).Interior.ColorIndex = 36
ElseIf MyCell.Value Like "*Approve with Mod*" Then
'Set the cell background color to light green
MyCell.Interior.ColorIndex = 35
MyCell.Offset(0, -5).Interior.ColorIndex = 35
MyCell.Offset(0, -4).Interior.ColorIndex = 35
MyCell.Offset(0, -3).Interior.ColorIndex = 35
MyCell.Offset(0, -2).Interior.ColorIndex = 35
MyCell.Offset(0, -1).Interior.ColorIndex = 35
MyCell.Offset(0, 1).Interior.ColorIndex = 35
ElseIf MyCell.Value Like "*Approve*" Then
'Set the cell background color to light periwinkle
MyCell.Interior.ColorIndex = 34
MyCell.Offset(0, -5).Interior.ColorIndex = 34
MyCell.Offset(0, -4).Interior.ColorIndex = 34
MyCell.Offset(0, -3).Interior.ColorIndex = 34
MyCell.Offset(0, -2).Interior.ColorIndex = 34
MyCell.Offset(0, -1).Interior.ColorIndex = 34
MyCell.Offset(0, 1).Interior.ColorIndex = 34
ElseIf MyCell.Value Like "*Withdrawal*" Then
'Set the cell background color to light purple
MyCell.Interior.ColorIndex = 39
MyCell.Offset(0, -5).Interior.ColorIndex = 39
MyCell.Offset(0, -4).Interior.ColorIndex = 39
MyCell.Offset(0, -3).Interior.ColorIndex = 39
MyCell.Offset(0, -2).Interior.ColorIndex = 39
MyCell.Offset(0, -1).Interior.ColorIndex = 39
MyCell.Offset(0, 1).Interior.ColorIndex = 39
ElseIf MyCell.Value Like "*Disposition*" Then
'Set the cell background color to lake blue
'MyCell.Interior.ColorIndex = 33
Else
'Set the cell background color to gray
MyCell.Interior.ColorIndex = 15
MyCell.Offset(0, -5).Interior.ColorIndex = 15
MyCell.Offset(0, -4).Interior.ColorIndex = 15
MyCell.Offset(0, -3).Interior.ColorIndex = 15
MyCell.Offset(0, -2).Interior.ColorIndex = 15
MyCell.Offset(0, -1).Interior.ColorIndex = 15
MyCell.Offset(0, 1).Interior.ColorIndex = 15
End If
Next
Loop
End Sub
Bookmarks