Set the Border Color of Excel Cells by VBA Color/ColorIndex Properties

You may use Borders.ColorIndex property to set the border color from available 56 color palette

How to set border colors of Excel Cells in VBA

  • You may use Borders.ColorIndex property to set the border color from the available 56 color palette
  • Excel cell border color can also be set with RGB colors by using Borders.Color property
  • The examples of using both ways are shown below with resultant sheets

An example of setting the border color by ColorIndex property

The ColorIndex property enables you to use the default color palette index from 1 to 56 values as shown below.


The example below shows setting the color of seven cells (A2 to G2) in our Excel sheet by using the ColorIndex property:


See all default colors in the Excel sheet by For..Next loop

In this example, we created a range of cells consisting of 56 cells.

In each cell, we will assign a seperate color code by ColorIndex property to each cell’s border.

VBA Code:



Using RGB color by Borders.Color property

If you need more color options beyond the 56 default color palette then you may set the color by RGB code.

VBA Borders.Color property can be used to set the color with RGB value.

The example below sets the color of five cells with RGB values:

VBA code: