CellFormat Object [Excel 2003 VBA Language Reference]

Multiple objects

Represents the search criteria for the cell format.

Using the CellFormat object

Use the FindFormat or ReplaceFormat properties of the Application object to return a CellFormat object.

With a CellFormat object, you can use the Borders ,Font , orInterior properties of the CellFormat object, to define the search criteria for the cell format. The following example sets the search criteria for the interior of the cell format. In this scenario, the interior of cell A1 is set to yellow, which is then found and replaced with a green interior.

Sub ChangeCellFormat()

    ' Set the interior of cell A1 to yellow.
    Selection.Interior.ColorIndex = 36
    MsgBox "The cell format for cell A1 is a yellow interior."

    ' Set the CellFormat object to replace yellow with green.
    With Application
        .FindFormat.Interior.ColorIndex = 36
        .ReplaceFormat.Interior.ColorIndex = 35
    End With

    ' Find and replace cell A1's yellow interior with green.
    ActiveCell.Replace What:="", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=True, _
    MsgBox "The cell format for cell A1 is replaced with a green interior."

End Sub

Properties | AddIndent Property | Application Property | Borders Property | Creator Property | Font Property | FormulaHidden Property | HorizontalAlignment Property | IndentLevel Property | Interior Property | Locked Property | MergeCells Property | NumberFormat Property | NumberFormatLocal Property | Orientation Property | Parent Property | ShrinkToFit Property | VerticalAlignment Property | WrapText Property

Methods | Clear Method

Parent Objects | Application Object

Child Objects | Borders Object | Font Object | Interior Object