Color of a border edge (1 Viewer)

AshikHusein

Registered User.
Local time
Today, 03:16
Joined
Feb 7, 2003
Messages
147
I am trying to get the color index number of an edge of a cell. So for example, for the cell B2 the code is

color_index = Range("B2").Borders(XlEdgeTop).ColorIndex

msgbox(color_index)

This returns -4142. But if I change the range to say A1 (which is a cell without a border), it still returns -4142

Am I using the correct VBA code for this? Thanks
 

RayH

Registered User.
Local time
Today, 00:16
Joined
Jun 24, 2003
Messages
132
I am trying to get the color index number of an edge of a cell. So for example, for the cell B2 the code is

color_index = Range("B2").Borders(XlEdgeTop).ColorIndex

msgbox(color_index)

This returns -4142. But if I change the range to say A1 (which is a cell without a border), it still returns -4142

Am I using the correct VBA code for this? Thanks

I get the same as you but using this:
color_index = Selection.Cells.Borders(xlEdgeTop).ColorIndex
returns the answer.

Of course you have to select the cell first.
 

unmarkedhelicopter

Registered User.
Local time
Today, 08:16
Joined
Apr 23, 2007
Messages
177
-4142 is the colour for xlnone (i.e. no colour)
The workbook colour ranges are determined by what the user has set (i.e. the user can displace colours out of the standard pallet)
There is a standard range of colours but you should be aware of the above.

The 'Standard' colours are :-
.ColorIndex = xlAutomatic ' Automatic
.ColorIndex = xlNone ' Clear
.ColorIndex = 1 ' Black
.ColorIndex = 2 ' White
.ColorIndex = 3 ' Red
.ColorIndex = 4 ' Bright Green
.ColorIndex = 5 ' Blue
.ColorIndex = 6 ' Yellow
.ColorIndex = 7 ' Pink
.ColorIndex = 8 ' Turquoise
.ColorIndex = 9 ' Dark Red
.ColorIndex = 10 ' Green
.ColorIndex = 11 ' Dark Blue
.ColorIndex = 12 ' Dark Yellow
.ColorIndex = 13 ' Violet
.ColorIndex = 14 ' Teal
.ColorIndex = 15 ' Grey 25%
.ColorIndex = 16 ' Grey 50%
.ColorIndex = 33 ' Sky Blue
.ColorIndex = 34 ' Light Turquoise
.ColorIndex = 35 ' Light Green
.ColorIndex = 36 ' Light Yellow
.ColorIndex = 37 ' Pale Blue
.ColorIndex = 38 ' Rose
.ColorIndex = 39 ' Lavender
.ColorIndex = 40 ' Tan
.ColorIndex = 41 ' Light Blue
.ColorIndex = 42 ' Aqua
.ColorIndex = 43 ' Lime
.ColorIndex = 44 ' Gold
.ColorIndex = 45 ' Light Orange
.ColorIndex = 46 ' Orange
.ColorIndex = 47 ' Blue-Grey
.ColorIndex = 48 ' Grey 40%
.ColorIndex = 49 ' Dark Teal
.ColorIndex = 50 ' Sea Green
.ColorIndex = 51 ' Dark Green
.ColorIndex = 52 ' Olive Green
.ColorIndex = 53 ' Brown
.ColorIndex = 54 ' Plum
.ColorIndex = 55 ' Indigo
.ColorIndex = 56 ' Grey 80%
 

Users who are viewing this thread

Top Bottom