Borders object (Excel)
A collection of four Border objects that represent the four borders of a Range object or Style object.
Remarks
Use the Borders property to return the Borders collection, which contains all four borders. You can apply different borders to each side of a cell or range. For more information how to apply borders to a range of cells, see Range.Borders property.
You can set border properties for an individual border only with Range and Style objects. Other bordered objects, such as error bars and series lines, have a border that's treated as a single entity, regardless of how many sides it has. For these objects, you must return and set properties for the entire border as a unit. For more information, see the Border object.
Examples
The following example adds a double border to cell A1 on worksheet one.
Worksheets(1).Range("A1").Borders.LineStyle = xlDouble
Use Borders (index), where index identifies the border, to return a single Border object. Index can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.
The following example sets the color of the bottom border of cells A1:G1 to red.
Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
The following example generates a thin border around all cells in the range.
Dim rng As Range: Set rng = ws.Range("B6", "D8")
With rng.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
The following example changes only the inner cell borders of the range.
Dim rngInner As Range: Set rngInner = ws.Range("B2", "D4")
With rngInner.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With rngInner.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
Properties
- Application
- Color
- ColorIndex
- Count
- Creator
- Item
- LineStyle
- Parent
- ThemeColor
- TintAndShade
- Value
- Weight
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.