??? How to get list of Color constants

G

Guest

I have the following code with colorindx number 1 representing black color,

May I know how do I get the related color constatn list (ie what number =
what color) in VBA

With Selection.Interior
.ColorIndex = 1
End With
 
G

Guest

Hi,
Not sure but try this one
Sub Colorindexinterior()
For r = 0 To 56 'max is 56 as I know
Cells(r + 1, 1).Interior.ColorIndex = r
Cells(r + 1, 1).Offset(0, 1) = Cells(r + 1, 1).Interior.ColorIndex
Next
End Sub

I don't know if colorindex conts is available
 
B

Bob Phillips

Here is an enumerated list which you can add to a module and then use the
colour constant name.

Public Enum xlColorIndex
xlCIBlack = 1
xlCIWhite = 2
xlCIRed = 3
xlCIBrightGreen = 4
xlCIBlue = 5
xlCIYellow = 6
xlCIPink = 7
xlCITurquoise = 8
xlCIDarkRed = 9
xlCIGreen = 10
xlCIDarkBlue = 11
xlCIDarkYellow = 12
xlCIViolet = 13
xlCITeal = 14
xlCIGray25 = 15
xlCIGray50 = 16
xlCIPeriwinkle = 17
xlCIPlum = 18
xlCIIvory = 19
xlCILightTurquoise = 20
xlCIDarkPurple = 21
xlCICoral = 22
xlCIOceanBlue = 23
xlCIIceBlue = 24
'xlCIDarkBlue = 25
'xlCIPink = 26
'xlCIYellow = 27
'xlCITurquoise = 28
'xlCIViolet = 29
'xlCIDarkRed = 30
'xlCITeal = 31
'xlCIBlue = 32
xlCISkyBlue = 33
xlCILightGreen = 35
xlCILightYellow = 36
xlCIPaleBlue = 37
xlCIRose = 38
xlCILavender = 39
xlCITan = 40
xlCILightBlue = 41
xlCIAqua = 42
xlCILime = 43
xlCIGold = 44
xlCILightOrange = 45
xlCIOrange = 46
xlCIBlueGray = 47
xlCIGray40 = 48
xlCIDarkTeal = 49
xlCISeaGreen = 50
xlCIDarkGreen = 51
xlCIBrown = 53
xlCIIndigo = 55
xlCIGray80 = 56
End Enum



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
J

Jim May

Bob,
Wasn't quite sure about use of enums, but I pasted the below into a
standard module; then only in the immediate window I entered:

Range("B4").Interior.ColorIndex = xlCIYellow

And it worked (suddenly my cell B4 turned yellow) Yikes,,,

My question is: If someone worked with and needed/wanted to
Use the this scheme index they would simply INCLUDE the 58 lines
As is into a standard module of either the: 1)Activeworkbook,
2)Personal.xls
Or 3)an add-in?

Thanks for your help,,
Jim May
 
B

Bob Phillips

Hi Jim,

In the workbook that the code that uses it is also in.

It gets better.

Create a simple sub like so


Sub SetColour(cell As Range, colour As xlColorIndex)
cell.Interior.ColorIndex = colour
End Sub

then in the immediate window, type

SetColour Activecell,

when you type the colour, you will see a list pop, intellisense just as with
other parts of VBA :). This will also happen when entering code normally.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

Bob,
Thanks .. much appreciated - have printed-off
your comments to study and commit to memory later.
Jim

Bob Phillips said:
Hi Jim,

In the workbook that the code that uses it is also in.

It gets better.

Create a simple sub like so


Sub SetColour(cell As Range, colour As xlColorIndex)
cell.Interior.ColorIndex = colour
End Sub

then in the immediate window, type

SetColour Activecell,

when you type the colour, you will see a list pop, intellisense just as with
other parts of VBA :). This will also happen when entering code normally.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

If you want to see a color chart, open the Visual Basic Editor and click
Help. Type in the search box "PatternColorIndex Property" without the quote
marks and then click on the same words when they show in the options panel.
This will display the chart with the numbers for the colors. If you print
the chart you will notice that your printer limits the amount of variation to
the colors based on the printer capabilities so that when printed, index
numbers 18, 29 and 54 might look the same when printed.
 

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