PDA

View Full Version : Solved: multiple interior.colorindex

lucsar
07-11-2011, 08:12 AM
Hi all,

I would like to color multi cells on a row at once without to repeat for each:

Dim Xcell As Range
For Each Xcell In Range("L8:R100")

If Cells(Xcell.Row, 15).Value = "x" Then
Cells(Xcell.Row, 33).Interior.ColorIndex = 3
Cells(Xcell.Row, 34).Interior.ColorIndex = 3
Cells(Xcell.Row, 35).Interior.ColorIndex = 3
Cells(Xcell.Row, 36).Interior.ColorIndex = 3
...

Thanks!
Luca

shrivallabha
07-11-2011, 08:33 AM
There are many ways to achieve this:
First is something you are already doing:
Dim Xcell As Range
For Each Xcell In Range("L8:R100")

If Cells(Xcell.Row, 15).Value = "x" Then
For i = 33 to 36 'Change to suit
Cells(Xcell.Row, i).Interior.ColorIndex = 3
Next i
End If

Next Xcell

You can use resize property as:
Cells(Xcell, 33).Resize(, 4).Interior.ColorIndex = 3

You can also use range as:
Range(Cells(Xcell, 33), Cells(Xcell, 36)).Interior.ColorIndex = 3

Bob Phillips
07-11-2011, 11:23 AM
Dim Xcell As Range
For Each Xcell In Range("L8:R100")

If Cells(Xcell.Row, 15).Value = "x" Then
Cells(Xcell.Row, 33).Resize(1, 4).Interior.ColorIndex = 3
End If
Next Xcell