0
1

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 2021-04-19

◆セルの塗りつぶし

セルの塗りつぶしはinterior.Colorプロパティを変更することで行う。
色は「色定数」若しくは「RGB値」で指定する。

セルの塗りつぶし
Sub sample1()
    '色定数での指定
    Range("A1").interior.Color = vbWhite ' 白
    Range("A2").interior.Color = vbBlack ' 黒
    Range("A3").interior.Color = vbRed ' 赤
    Range("A4").interior.Color = vbBlue ' 青
    Range("A5").interior.Color = vbGreen ' 緑
    Range("A6").interior.Color = vbMagenta ' マゼンタ
    Range("A7").interior.Color = vbCyan ' シアン
    Range("A8").interior.Color = vbYellow ' 黄

    'RGB値での指定(サンプルは色相環12分割)
    Range("C1").interior.Color = RGB(255,0,0)
    Range("C2").interior.Color = RGB(255,127,0)
    Range("C3").interior.Color = RGB(255,255,0)
    Range("C4").interior.Color = RGB(127,255,0)
    Range("C5").interior.Color = RGB(0,255,0)
    Range("C6").interior.Color = RGB(0,255,127)
    Range("C7").interior.Color = RGB(0,255,255)
    Range("C8").interior.Color = RGB(0,127,255)
    Range("C9").interior.Color = RGB(0,0,255)
    Range("C10").interior.Color = RGB(127,0,255)
    Range("C11").interior.Color = RGB(255,0,255)
    Range("C12").interior.Color = RGB(255,0,127)
End Sub

◆セルの塗りつぶしの解除

塗りつぶしの解除は次のように記述する。
interior.ColorIndexの値を変更することに注意。

セルの塗りつぶし
Sub sample2()
    Range("E1:G3").interior.Color = vbRed  

    '塗りつぶし解除
    Range("F2").interior.ColorIndex = xlNone
end Sub
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?