BorderAround Method

Applies To

Range object.

Description

Adds a border to a range and sets the Color, LineStyle, and Weight properties for the new border.

Syntax

expression.BorderAround(LineStyle, Weight, ColorIndex, Color)

expression Required. An expression that returns a Range object.

LineStyle Optional Variant. The line style for the border. Can be one of the following XlBorderLineStyle constants: xlBorderLineStyleNone, xlBorderLineStyleContinuous, xlBorderLineStyleDash, xlBorderLineStyleDot, or xlBorderLineStyleDouble. The default value is xlBorderLineStyleContinuous.

Weight Optional Variant. The border weight. Can be one of the following XlBorderWeight constants: xlHairline, xlThin, xlMedium, or xlThick. The default value is xlThin.

ColorIndex Optional Variant. The border color, as an index into the current color palette, or as one of the following XlColorIndex constants: xlColorIndexAutomatic or xlColorIndexNone.

Color Optional Variant. The border color, as an RGB value.

Remarks

You can specify either ColorIndex or Color, but not both. If you don't specify either argument, Microsoft Excel uses the xlAutomatic color index.

Similarly, you can specify either LineStyle or Weight, but not both. If you don't specify either argument, Microsoft Excel creates a default border.

This method outlines the entire range without filling it in. To set the borders of all the cells, you must set the Color, LineStyle, and Weight properties for the Borders collection. To clear the border, you must set the LineStyle property to xlBorderLineStyleNone for all the cells in the range.

Example

This example adds a thick red border around the range A1:D4 on Sheet1.

Worksheets("Sheet1").Range("A1:D4").BorderAround _
        ColorIndex:=3, Weight:=xlThick