Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ColorIndex or RGB value

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
0
0
BE
I have an export from access to excel along vba.

Code:
xlWorkSheet.Cells(iRow, iCol).InteriorColor = ....

In the excel file there are some predefined colors. I need to discover the RGB or ColorIndex number from these colors. How can I get, discover this ?
 
I understand you want to see which interior color number that is defined for a specific cell. Here's one way:

Code:
Sub a()

iRow = 1
iCol = 1

oRow = 1
oCol = 2

Cells(iRow, iCol).Select
c = Selection.Interior.Color

Cells(oRow, oCol) = c

End Sub

This code will output the interior color of cell A1 and put the value in cell B1.
 
WorkbookReference.Colors(ColorIndex) gives an access (get/set) to given colour index (palette).
You can set cell's colour either using ColorIndex or Color, in the latter case the closest colour from current palette will be applied.

combo
 
the excel palette is 56 colours.

this will copy the colorindex, the color itself and its hex rgb value into the current sheet:

Code:
Sub Boing()
Dim i As Integer
For i = 0 To 56 ' zero is white as is 2
  With Selection.Offset(i, 0)
    .Formula = i
    With .Offset(0, 1).Interior
        .ColorIndex = i
        .Pattern = xlSolid
    End With
    .Offset(0, 2).Value = "'" & Right$("000000" & Hex$(.Offset(0, 1).Interior.Color), 6)
  End With
Next
End Sub



mr s. <;)

 
Thanks to all. Misterstick, I run you're code and I got a nice list of the Indexnumbers. So I could detect the corresponding indexnumber and implement this in my code.

 
I think the easiest way is to open a new spreadsheet, create a new macro, and then just change cells to the colors that you need the index for. You can then just open the code from the macro, and it will give you the colorindex that you just created.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top