VBA Help:Change Color of Cells

  • Thread starter Thread starter Robert Lie
  • Start date Start date
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
 
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
 
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
 
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
 

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

Back
Top