0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VBA:「条件付き書式」を特定列を条件として範囲に設定

Last updated at Posted at 2020-07-22

目的

  • 「A2:G100」の範囲に対して条件付き書式を設定する。条件と書式は次の通り。
  • 「A2」を開始セルとする列が空白の場合、対象行を赤色にする。
  • ※条件付き書式を範囲に設定することで、ループせずに行の書式を変えられる。

コード

Sub setFormatCondition()

  'A2:G100の範囲に条件を設定
  With Sheet3.Range("A2:G100")
    ' Typeは数式(xlExpression)。
    '「$A」で列全体を指定
    'Fomula1で空白の場合の条件を設定。
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:="=$A2="""""
    .FormatConditions(1).SetFirstPriority
    With .FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
  End With

End Sub

結果

image.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?