VBA: Color Reference For Colorindex

August 18th, 2004 | Categories: VBA | Tags: , ,

When using VBA to code the Colorindex (or background color) of a cell it is useful to know what integer will equal what color. Below is a reference picture which shows the color and lists it’s respective Colorindex. aka VBA Color Palette

ColorReference


Here’s the code to make one for yourself, or just bookmark the permalink:

Sub ColorRef()
Dim x As Integer

For x = 1 To 56

If x < 29 Then
Cells(x, 1).Interior.ColorIndex = x
Cells(x, 2) = x
Else
Cells(x - 28, 3).Interior.ColorIndex = x
Cells(x - 28, 4) = x
End If

Next x

End Sub
  1. July 31st, 2008 at 17:03
    Reply | Quote | #1

    Thanks, works great.

    However, Why does excel give 56 numbers to 35 colors?

    Thanks again.

  2. Les Z
    January 16th, 2009 at 19:45
    Reply | Quote | #2

    thanks for this. simple but very helpful.

  3. Miguel
    May 21st, 2009 at 14:51
    Reply | Quote | #3

    I would like to biuld a macro to delete a whole row if the color of the cell in row X is red. Can you help me with this?
    I tried this
    Sub Delete_Low_Volume()

    Dim WatchRange As Range
    Dim CellTest As Range

    Set WatchRange = Range(“X:X”)

    For Each CellTest In WatchRange.Cells
    If ActiveCell.Interior.ColorIndex = 4 Then
    ActiveCell.EntireRow.Delete
    ‘ActiveCell.Offset(0, -1).Range(“A1″).Select

    End If
    Next CellTest

    End Sub

    but it is deleting me everything. all the rows. I don’t know if it may be because of the fact that I’m using conditional formating with cells in row X.

    Thanks!

    • WillMC
      February 7th, 2010 at 02:54
      Reply | Quote | #4

      This was fast and dirty. Simple to use and debug.

      Sub colordel()

      Do
      Range(“A1″).Select

      ‘ Looks for a blank cell and stops the loop.
      ender = ActiveCell.Value

      If ActiveCell.Interior.ColorIndex = 4 Then GoTo 12

      ActiveCell.EntireRow.Delete
      ActiveCell.Offset(-1, 0).Select

      12
      ActiveCell.Offset(1, 0).Select
      Loop Until ender = “”

      End Sub

  4. SarikaG
    February 18th, 2010 at 18:28
    Reply | Quote | #5

    This was very helpful, Thanks for sharing.

  5. 1 trackbacks