Article ID: 183022
Article Last Modified on 6/17/2005
ActiveCell.Borders.ColorIndex = 3
ActiveCell.Borders(xlEdgeLeft).ColorIndex = 2 ActiveCell.Borders(xlEdgeRight).ColorIndex = 3 ActiveCell.Borders(xlEdgeTop).ColorIndex = 4 ActiveCell.Borders(xlEdgeBottom).ColorIndex = 5You can set all four borders to the same value by using a line of code similar to the following:
ActiveCell.Borders.ColorIndex = 6
Selection.Borders(xlInsideVertical).ColorIndex = 7 Selection.Borders(xlInsideHorizontal).ColorIndex = 8NOTE: When you use the xlInsideVertical constant, the selected range must contain at least two columns. When you use the xlInsideHorizontal constant, the selected range must contain at least two rows. If the selection does not contain the necessary number of columns or rows, you receive the following error message:
With Selection.Borders(xlDiagonalUp)
.Weight = xlThin
.ColorIndex = 9
End With
-or-
Selection.Borders(xlDiagonalDown).Weight = xlMedium Selection.Borders(xlDiagonalDown).ColorIndex = 10NOTE: If you use the ColorIndex property of the diagonal border before you set its Weight property, the ColorIndex property is ignored, and the border appears in the default color (black). If you do not set the Weight property, the border does not appear.
MsgBox ActiveCell.Borders.Counta message box with the number of borders for the active cell appears. By running this macro, you can determine that a cell contains six borders: left, right, top, bottom, diagonal up, and diagonal down. However, if you specify a color for all six borders by running a macro that uses the following line of code
ActiveCell.Borders.ColorIndex = 3the color for only the first four borders is changed. The color for the diagonal borders is not changed because no weight is specified for them. Note that you can use the workaround in this article to force the diagonal borders to appear.
Additional query words: XL98
Keywords: kbbug kbprogramming kbdtacode KB183022