Mataunited18
Mataunited18

Reputation: 628

VBA Color entire row based on the ColorIndex in a table

I have a table where column E consists of ColorIndex

I have extracted the color index from the cells in Sheet1 using below code,

Function BGCol(ThisCell As Range) As Long
BGCol = ThisCell.Interior.ColorIndex
End Function

and pasted the ColorIndex value sto Sheet2. How can I color the entire rows based on the ColorIndex that I now got. The values are -4142,19,35,36,38, and 43. I have a table in Sheet2 where column E consists of ColorIndex values.

Upvotes: 1

Views: 1040

Answers (1)

Mikku
Mikku

Reputation: 6654

Something like this will work:

ActiveSheet.Rows(2).Interior.ColorIndex = Range("E2").Value

Put it in a Loop to and change the Row Index and Range Index.

Like:

With Worksheets("Sheet2")

For i = 1 To 100

     .Rows(i).Interior.ColorIndex = .Range("E" & i).Value

Next

End With

Upvotes: 2

Related Questions