備考
ある範囲に対して3つ以上の条件付き形式を定義することはできません。既存の条件付き形式を変更するには、Modifyメソッドを使用します。新しい形式を追加する前に、既存の形式を削除するには、Deleteメソッドを使用します。
構文:
FormatConditions.Add(Type, Operator, Formula1, Formula2)
パラメーター:
| 名 | 必須/オプション | データ・タイプ |
|---|
| タイプ | 必須 | XlFormatConditionType |
| オペレーター | オプション | バリアント |
| 式1 | オプション | バリアント |
| フォーミュラ2 | オプション | バリアント |
| 名 | 説明 |
|---|
| xlAboveAverageCondition | 上記平均状態 |
| xlBlanksCondition | ブランク条件 |
| xlCellValue | セル値 |
| xlColorScale | カラースケール |
| xlDatabar | データバー |
| xlErrorsCondition | エラー条件 |
| xl式 | 式 |
| XlIconSet | アイコンセット |
| xlNoBlanksCondition | ブランク条件なし |
| xlNoErrorsCondition | エラーなし条件 |
| xlTextString | テキスト文字列 |
| xlTimePeriod | 期間 |
| xlTop10 | 上位10の値 |
| xlUniqueValues | 一意の値 |
セル値による書式設定:
With Range("A1").FormatConditions.Add(xlCellValue, xlGreater, "=100")
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
オペレーター:
| 名 |
|---|
| xlBetween |
| xlEqual |
| xlGreater |
| xlGreaterEqual |
| xlLess |
| xlLessEqual |
| xlNotBetween |
| xlNotEqual |
TypeがxlExpressionの場合、Operator引数は無視されます。
テキストによる書式設定には、
With Range("a1:a10").FormatConditions.Add(xlTextString, TextOperator:=xlContains, String:="egg")
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
オペレーター:
| 名 | 説明 |
|---|
| xlBeginsWith | 指定された値で開始します。 |
| xlコンテナ | 指定された値を含みます。 |
| xlDoesNotContain | 指定された値を含んでいません。 |
| xlEndsWith | 指定された値で終了 |
期間別の書式設定
With Range("a1:a10").FormatConditions.Add(xlTimePeriod, DateOperator:=xlToday)
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
オペレーター:
| 名 |
|---|
| xl昨日 |
| 明日 |
| xlLast7Days |
| xlLastWeek |
| xlThisWeek |
| xlNextWeek |
| xlLastMonth |
| xlThisMonth |
| xlNextMonth |
条件付きフォーマットを削除する
範囲内のすべての条件付きフォーマットを削除する:
Range("A1:A10").FormatConditions.Delete
ワークシートのすべての条件付きフォーマットを削除します。
Cells.FormatConditions.Delete
重複した値を強調表示する
With Range("E1:E100").FormatConditions.AddUniqueValues
.DupeUnique = xlDuplicate
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
ユニークな値の強調
With Range("E1:E100").FormatConditions.AddUniqueValues
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
上位5つの値を強調表示する
With Range("E1:E100").FormatConditions.AddTop10
.TopBottom = xlTop10Top
.Rank = 5
.Percent = False
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
With Range("E1:E100").FormatConditions.AddAboveAverage
.AboveBelow = xlAboveAverage
With .Font
.Bold = True
.ColorIndex = 3
End With
End With
オペレーター:
| 名 | 説明 |
|---|
| XlAboveAverage | 平均以上 |
| XlAboveStdDev | 標準偏差より大きい |
| XlBelowAverage | 平均以下の |
| XlBelowStdDev | 標準偏差以下 |
| XlEqualAboveAverage | 平均以上 |
| XlEqualBelowAverage | 平均以下 |
Range("a1:a10").FormatConditions.AddIconSetCondition
With Selection.FormatConditions(1)
.ReverseOrder = False
.ShowIconOnly = False
.IconSet = ActiveWorkbook.IconSets(xl3Arrows)
End With
With Selection.FormatConditions(1).IconCriteria(2)
.Type = xlConditionValuePercent
.Value = 33
.Operator = 7
End With
With Selection.FormatConditions(1).IconCriteria(3)
.Type = xlConditionValuePercent
.Value = 67
.Operator = 7
End With
IconSet:
| 名 |
|---|
| xl3Arrows |
| xl3ArrowsGray |
| xl3Flags |
| xl3署名 |
| xl3スターズ |
| xl3シンボル |
| xl3シンボル2 |
| xl3TrafficLights1 |
| xl3TrafficLights2 |
| xl3三角形 |
| xl4Arrows |
| xl4ArrowsGray |
| xl4CRV |
| xl4RedToBlack |
| xl4TrafficLights |
| xl5Arrows |
| xl5ArrowsGray |
| xl5Boxes |
| xl5CRV |
| xl5クォーターズ |
タイプ:
| 名 |
|---|
| xlConditionValuePercent |
| xlConditionValueNumber |
| xlConditionValuePercentile |
| xlConditionValueFormula |
オペレーター:
| 名 | 値 |
|---|
| xlGreater | 5 |
| xlGreaterEqual | 7 |
値:
条件付き形式でアイコンのしきい値を返すか設定します。