VBA Help:Change Color of Cells

R

Robert Lie

Dear All,

How to change the color of cells?
I'm confused whether to use range object or cells object.
Pls give me example.

Thanks

Robert Lie
 
N

Norman Jones

Hi Robert,

The Cells property returns a range object, so you could, for example, use
either of the following equivalent instructions:


Range("A1:A10").Interior.ColorIndex = 6

Cells(1, 1).Resize(10).Interior.ColorIndex = 6
 
R

Robert Lie

Hi All,

I need give a specific color for the cells.
Do you could give me the list of colorindex, since I couldn't find the
list from VBA Help?

Thanks

Robert Lie
 
N

Norman Jones

Hi Robert,

With a blank worksheet active try:

'===============>>
Sub ColourTable()
Dim iCtr As Long

For iCtr = 1 To 56
Cells(iCtr, 1).Interior.ColorIndex = iCtr
Cells(iCtr, 2).Value = "'" & Right("000000" & _
Hex(ThisWorkbook.Colors(iCtr)), 6)
Cells(iCtr, 3).Value = iCtr
Cells(iCtr, 4).Value = Cells(iCtr, 1).Interior.Color
Cells(iCtr, 2).Font.Name = "Courier New"
Cells(iCtr, 2).HorizontalAlignment = xlRight
Cells(iCtr, 3).HorizontalAlignment = xlCenter
Cells(iCtr, 4).HorizontalAlignment = xlLeft
Next iCtr

End Sub
'<<===============

See also David McRitchie's Color page at:

http://www.mvps.org/dmcritchie/excel/colors.htm
 
Top