Skip to content

Latest commit

 

History

History
88 lines (63 loc) · 2.94 KB

Excel.Borders.md

File metadata and controls

88 lines (63 loc) · 2.94 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
Borders object (Excel)
vbaxl10.chm180072
vbaxl10.chm180072
Excel.Borders
adb6efd6-73b6-e620-e9be-f4a42bc52ae8
03/29/2019
medium

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

See also

[!includeSupport and feedback]