Fill Cells with Red

G

Guest

I have a spreadsheet that I need to fill the interior color of the row red if
column f contains the text red. I need the data in each row to turn red if f
is red for columns a through e and g through m.
Is there an easy way to do this other than sorting/filtering. I have
already used the conditional formatting option for another purpose. Is there
some
way to do this with VBA?

Any help is appreciated.
 
G

Guest

Sub cb()
n = Cells(Rows.Count, "F").End(xlUp).Row
For i = 1 To n
If Cells(i, "F").Value = "red" Then
Range("A" & i & ":E" & i).Interior.ColorIndex = 3
Range("G" & i & ":M" & i).Interior.ColorIndex = 3
End If
Next
End Sub
 
G

Guest

Thanks Gary. This is just what I needed.

Gary''s Student said:
Sub cb()
n = Cells(Rows.Count, "F").End(xlUp).Row
For i = 1 To n
If Cells(i, "F").Value = "red" Then
Range("A" & i & ":E" & i).Interior.ColorIndex = 3
Range("G" & i & ":M" & i).Interior.ColorIndex = 3
End If
Next
End Sub
 
J

JE McGimpsey

One way:

Put this in your worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rIntersect As Range
Dim rCell As Range
Dim nCI As Long
Set rIntersect = Intersect(Target, Columns("F"))
If Not rIntersect Is Nothing Then
For Each rCell In rIntersect
With rCell
If LCase(rCell.Text) = "red" Then
nCI = 3
Else
nCI = xlColorIndexNone
End If
Union(.Offset(0, -5).Resize(1, 5), _
.Offset(0, 1).Resize(1, 7)).Interior.ColorIndex = nCI
End With
Next rCell
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top