Format related procedures in class Range (Excel VBA)

This page presents procedures from class Range related to the theme Format: ApplyOutlineStyles, BorderAround, Borders, ClearFormats, ColumnWidth, DisplayFormat, Font, FormatConditions, Height, Left, NumberFormat, NumberFormatLocal, RowHeight, Style, Top, UseStandardHeight, UseStandardWidth and Width

ApplyOutlineStyles

Applies outlining styles to the specified range.

Selection.ApplyOutlineStyles

BorderAround

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

You must specify only one of the following: ColorIndex, Color, or ThemeColor. You can specify either LineStyle or Weight, but not both. If you don't specify either argument, Microsoft Excel uses the default line style and weight. 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 xlLineStyleNone for all the cells in the range.

BorderAround (LineStyle, Weight, ColorIndex, Color, ThemeColor)

Dim brdBorderAround As Border
Set brdBorderAround = ActiveCell.BorderAround()

Arguments

The following arguments are optional

LineStyle (XlLineStyle) - One of the constants of XlLineStyle specifying the line style for the border.

Possible Values are

xlContinuous Continuous line.
xlDash Dashed line.
xlDashDot Alternating dashes and dots.
xlDashDotDot Dash followed by two dots.
xlDot Dotted line.
xlDouble Double line.
xlLineStyleNone No line.
xlSlantDashDot Slanted dashes.

Weight (XlBorderWeight) - The border weight.

Possible Values are

xlHairline Hairline (thinnest border).
xlMedium Medium.
xlThick Thick (widest border).
xlThin Thin.

ColorIndex (XlColorIndex) - The border color, as an index into the current color palette or as an XlColorIndex constant.

Possible Values are xlColorIndexAutomatic - Automatic color, xlColorIndexNone - No color.

Color (Long) - The border color, as an RGB value.

ThemeColor (XlThemeColor) - The theme color, as an index into the current color theme or as an XlThemeColor value.

Here you can find possible values for XlThemeColor.

Borders

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).

Dim brdsBorders As Borders
Set brdsBorders = ActiveCell.Borders

ClearFormats

Clears the formatting of the object.

Worksheets("Sheet1").Range("A1:G37").ClearFormats

ColumnWidth

Returns or sets the width of all columns in the specified range. Read/write Double.

One unit of column width is equal to the width of one character in the Normal style. For proportional fonts, the width of the character 0 (zero) is used. Use the AutoFit method to set column widths based on the contents of cells. Use the Width property to return the width of a column in points. If all columns in the range have the same width, the ColumnWidth property returns the width. If columns in the range have different widths, this property returns null.

ActiveCell.ColumnWidth = 50

DisplayFormat

Returns a DisplayFormat object that represents the display settings for the specified range.

DisplayFormat is affected by conditional formatting as shown in the code below. It adds conditional formatting to Cell A1 on the ActiveSheet. This formatting bolds the cell, changes the interior color to red and adds a checker pattern.

Dim dftDisplayFormat As DisplayFormat
Set dftDisplayFormat = ActiveCell.DisplayFormat

Font

Returns a Font object that represents the font of the specified object.

Dim fntFont As Font
Set fntFont = ActiveCell.Font

FormatConditions

Returns a FormatConditions collection that represents all the conditional formats for the specified range.

Dim fcdsFormatConditions As FormatConditions
Set fcdsFormatConditions = ActiveCell.FormatConditions

Height

Returns a Double value that represents the height, in points, of the range. Read-only.

To set the height, use the RowHeight property.

Dim pntsHeight As Points
Set pntsHeight = ActiveCell.Height

Left

Returns a Variant value that represents the distance, in points, from the left edge of column A to the left edge of the range.

If the range is discontinuous, the first area is used. If the range is more than one column wide, the leftmost column in the range is used.

Dim lngLeft As Long
lngLeft = ActiveCell.Left

NumberFormat

Returns or sets a value that represents the format code for the object.

This property returns Null if all cells in the specified range don't have the same number format. The format code is the same string as the Format Codes option in the Format Cells dialog box. The Format function uses different format code strings than do the NumberFormat and NumberFormatLocal properties. For more information, see Number format codes (Microsoft Support).

Worksheets("Sheet1").Range("A17").NumberFormat = "General" 
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss" 
Worksheets("Sheet1").Columns("C"). _ 
 NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

NumberFormatLocal

Returns or sets a value that represents the format code for the object as a string in the language of the user.

The Format function uses different format code strings than do the NumberFormat and NumberFormatLocal properties. For more information, see Number format codes (Microsoft Support).

ActiveCell.NumberFormatLocal =

RowHeight

Returns or sets the height of the first row in the range specified, measured in points. Read/write Double.

The RowHeight property sets the height for all rows in a range of cells. Use the AutoFit method to set row heights based on the contents of cells. If a merged cell is in the range, RowHeight returns Null for varied row heights. Use the Height property to return the total height of a range of cells. When a range contains rows of different heights, RowHeight might return the height of the first row or might return Null.

ActiveCell.RowHeight = 40

Style

Returns or sets a Variant value containing a Style style that represents the style of the specified range.

Worksheets("Sheet1").Range("A1").Style = "Normal"

Top

Returns a Variant value that represents the distance, in points, from the top edge of row 1 to the top edge of the range.

If the range is discontinuous, the first area is used. If the range is more than one row high, the top (lowest numbered) row in the range is used.

Dim lngTop As Long
lngTop = ActiveCell.Top

UseStandardHeight

True if the row height of the Range object equals the standard height of the sheet. Returns Null if the range contains more than one row and the rows aren't all the same height.

ActiveCell.UseStandardHeight = True

UseStandardWidth

True if the column width of the Range object equals the standard width of the sheet. Returns null if the range contains more than one column and the columns aren't all the same width.

ActiveCell.UseStandardWidth = True

Width

Returns a Double value that represents the width of a range in points. Read-only.

To set the width, use the ColumnWidth property.

Dim dblWidth As Double
dblWidth = ActiveCell.Width