CellFormat 对象

         
Application
CellFormat
多个对象

表示单元格格式的搜索条件。

CellFormat 对象的用法

使用 ApplicationFindFormatReplaceFormat 属性可返回一个 CellFormat 对象。

对于 CellFormat 对象,可使用其 BordersFontInterior 属性为单元格格式定义搜索条件。下例为单元格内部格式设置搜索条件。在这个方案中,将单元格 A1 的内部设置为黄色,然后搜索到该单元格并且将其内部替换为绿色。

Sub ChangeCellFormat()

    ' Set the interior of cell A1 to yellow.
    Range("A1").Select
    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, _
        ReplaceFormat:=True
    MsgBox "The cell format for cell A1 is replaced with a green interior."

End Sub