Borders Property

Microsoft Excel Visual Basic

Show All

Borders Property

       

Borders property as it applies to the CellFormat object.

Allows the user to set or return the search criteria based on the cell's border format.

expression.Borders

expression   Required. An expression that returns a CellFormat object.

Borders property as it applies to the FormatCondition, Range, and Style objects.

Returns a  Borders collection that represents the borders of a style or a range of cells (including a range defined as part of a conditional format).

expression.Borders

expression   Required. An expression that returns one of the above objects.

Remarks

For information about returning a single member of a collection, see Returning an Object from a Collection.

Example

As it applies to the CellFormat object.

This example sets the search criteria to identify the borders of cells that have a continuous and thick style bottom-edge, creates a cell with this condition, finds this cell, and notifies the user. Note: The default color of the border is used in this example, therefore the color index is not changed.

Sub SearchCellFormat()

    ' Set the search criteria for the border of the cell format.
    With Application.FindFormat.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThick
    End With

    ' Create a continuous thick bottom-edge border for cell A5.
    Range("A5").Select
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThick
    End With
    Range("A1").Select
    MsgBox "Cell A5 has a continuous thick bottom-edge border"

    ' Find the cells based on the search criteria.
    Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=True).Activate
    MsgBox "Microsoft Excel has found this cell matching the search criteria."

End Sub

As it applies to the FormatCondition, Range, and Style objects.

This example sets the color of the bottom border of cell B2 on Sheet1 to a thin red border.

Sub SetRangeBorder()

    With Worksheets("Sheet1").Range("B2").Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 3
    End With

End Sub