Color index values

H

Hari

Hi,

In VB I want to use the fill color option based on certain conditions.

I know that yellow has a color index value 6.

I want to know where I can find a glossary for all the color index values.

Please tell me the source for the same. I searched in MS VB help but couldnt
find the same.

Regards,
Hari
India
 
W

William

Hari

Run this code on an empty worksheet.

Sub CheckColorIndex()
'by Wilson -- creates colour chart on worksheet
Dim CurrVal As Integer
Dim ColorChart As Range
Dim cell As Range
Set ColorChart = Range("A1:G8")
CurrVal = 1
For Each cell In ColorChart
With cell
..Value = CurrVal
..Font.Size = 14
..Font.Bold = True
..Font.ColorIndex = 2
..Interior.ColorIndex = cell.Value
..Interior.Pattern = xlSolid
CurrVal = CurrVal + 1
End With
Next cell
End Sub

--
XL2002
Regards

William

[email protected]

| Hi,
|
| In VB I want to use the fill color option based on certain conditions.
|
| I know that yellow has a color index value 6.
|
| I want to know where I can find a glossary for all the color index values.
|
| Please tell me the source for the same. I searched in MS VB help but
couldnt
| find the same.
|
| Regards,
| Hari
| India
|
|
|
|
|
 
H

Harald Staff

Hi Hari

See if David McRitchie's
http://www.mvps.org/dmcritchie/excel/colors.htm
is of help. And this little macro:


Sub Colors()
Dim L As Long
For L = 1 To 56
Cells(L, 1).Interior.ColorIndex = L
Cells(L, 2).Font.ColorIndex = L
Cells(L, 2).Value = "Colorindex " & L
Cells(L, 3).Value = "Colorindex " & L
Next
End Sub

HTH. Best wishes Harald
 
B

Bob Phillips

Lockup ColorIndex property in VBA Help.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

Doug Glancy

Hari,

You can run this in an empty worksheet:

Sub test()

Dim i As Double

i = 0
On Error Resume Next
ActiveSheet.Cells.Clear

While Err = 0
i = i + 1
ActiveSheet.Cells(i, 1) = i
ActiveSheet.Cells(i, 2).Interior.ColorIndex = i
Wend

ActiveSheet.Cells(i, 1).Clear

End Sub

hth,

Doug Glancy
 
D

Doug Glancy

Sure. Until I wrote it I didn't know how many colors there were. Plus, I
didn't know if there were more colors in later versions than my xl2000.

Doug
 
D

David McRitchie

Hi Doug,
If that is a question, 56 colors in the palette in all current versions of Excel.

As far as the future goes use Dimension as long instead of integer,
then if Excel is changed you'll be in better shape.

HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm


Doug Glancy said:
Sure. Until I wrote it I didn't know how many colors there were. Plus, I
didn't know if there were more colors in later versions than my xl2000.

Doug
 
D

Doug Glancy

Could you expand on the Dimension comment? I actually Dimensioned as a
Double, not Integer, although normally I would have done a Long, but I
thought I read a post somewhere that Double was more efficient since it was
native.

As Pikus said earlier today "learn the basics and then you won't be
confused."

!

Doug

David McRitchie said:
Hi Doug,
If that is a question, 56 colors in the palette in all current versions of Excel.

As far as the future goes use Dimension as long instead of integer,
then if Excel is changed you'll be in better shape.

HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm
 
D

David McRitchie

Hi Doug,
This should look familiar:
It would be looking for a whole number not something with a decimal
fraction. And long works faster than 2 byte integer anyway -- at least
that's what I think I've read in the newsgroups.

Long Data Type
Long (long integer) variables are stored as signed 32-bit (4-byte)
numbers ranging in value from -2,147,483,648 to 2,147,483,647.
The type-declaration character for Long is the ampersand (&).


Double Data Type
Double (double-precision floating-point) variables are stored as
IEEE 64-bit (8-byte) floating-point numbers ranging in value
from -1.79769313486231E308 to -4.94065645841247E-324
for negative values and from 4.94065645841247E-324 to
1.79769313486232E308 for positive values.
The type-declaration character for Double is the number sign (#).
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

Doug Glancy said:
Could you expand on the Dimension comment? I actually Dimensioned as a
Double, not Integer, although normally I would have done a Long, but I
thought I read a post somewhere that Double was more efficient since it was
native.

As Pikus said earlier today "learn the basics and then you won't be
confused."

!

Doug

David McRitchie said:
Hi Doug,
If that is a question, 56 colors in the palette in all current versions of Excel.

As far as the future goes use Dimension as long instead of integer,
then if Excel is changed you'll be in better shape.

HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm


Doug Glancy said:
Sure. Until I wrote it I didn't know how many colors there were. Plus, I
didn't know if there were more colors in later versions than my xl2000.

Doug

I prefer

For x = 1 To 56
Cells(x, 1).Interior.ColorIndex = x
Next x

- Pikus
 
D

Doug Glancy

David,

Thanks. I'm a little less confused now!

Doug

David McRitchie said:
Hi Doug,
This should look familiar:
It would be looking for a whole number not something with a decimal
fraction. And long works faster than 2 byte integer anyway -- at least
that's what I think I've read in the newsgroups.

Long Data Type
Long (long integer) variables are stored as signed 32-bit (4-byte)
numbers ranging in value from -2,147,483,648 to 2,147,483,647.
The type-declaration character for Long is the ampersand (&).


Double Data Type
Double (double-precision floating-point) variables are stored as
IEEE 64-bit (8-byte) floating-point numbers ranging in value
from -1.79769313486231E308 to -4.94065645841247E-324
for negative values and from 4.94065645841247E-324 to
1.79769313486232E308 for positive values.
The type-declaration character for Double is the number sign (#).
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

Could you expand on the Dimension comment? I actually Dimensioned as a
Double, not Integer, although normally I would have done a Long, but I
thought I read a post somewhere that Double was more efficient since it was
native.

As Pikus said earlier today "learn the basics and then you won't be
confused."

!

Doug

David McRitchie said:
Hi Doug,
If that is a question, 56 colors in the palette in all current
versions of
Excel.
As far as the future goes use Dimension as long instead of integer,
then if Excel is changed you'll be in better shape.

HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm


Sure. Until I wrote it I didn't know how many colors there were.
Plus,
I
didn't know if there were more colors in later versions than my xl2000.

Doug

I prefer

For x = 1 To 56
Cells(x, 1).Interior.ColorIndex = x
Next x

- Pikus
 
S

scottnshelly

I am very impressed with all of the examples given here. I am stil
very new to the whole Macro/VBA scene. i am only used to writing code
out of neccessity, but are there any more "fun" codes like these tha
you can give me? I mean, codes that don't actually do anything ver
important, but just are fun to watch or do? do you know what i mean
 
P

pikus

I wrote a cool little program that looped through all the colors an
assigned a different one to each cell's interior. I got a really coo
pattern since the screen can only display so many colors at a time I
was especially cool when I filled them in diagonally (A1, A2, B1, A3
B2, C1, etc...) I lost the code I used, but it was pretty easy in th
first place. Like this:

For r = 1 To 255
For g = 1 To 255
For b = 1 To 255
blah blah blah = (r, g, b)
Next b
Next g
Next r

- Piku
 
Top