色付けに関わるプロパティ
ColorIndexプロパティ、Colorプロパティを使って色を指定すると、セルの背景と文字の色を変えられます。
毎回打ち込むのも面倒なので、色付けの範囲ごとにコピペ用にまとめておきます。
Public Sub Sample()
Cells(1, 1) = "あいうえお" 'わかりやすいように文字を入力
'指定した範囲の色付け
Range("A1").Interior.ColorIndex = 5 '青
Range("A1").Interior.Color = RGB(255, 0, 0) '赤
Range("A1").Font.ColorIndex = 2 '白
Range("A1").Font.Color = RGB(0, 0, 0) '黒
Cells(1, 1).Interior.ColorIndex = 5
Cells(1, 1).Interior.Color = RGB(255, 0, 0)
Cells(1, 1).Font.ColorIndex = 2
Cells(1, 1).Font.Color = RGB(0, 0, 0)
'行の色付け
Rows(1).Interior.ColorIndex = 5
Rows(1).Interior.Color = RGB(255, 0, 0)
Rows(1).Font.ColorIndex = 2
Rows(1).Font.Color = RGB(0, 0, 0)
'列の色付け
Columns(1).Interior.ColorIndex = 5
Columns(1).Interior.Color = RGB(255, 0, 0)
Columns(1).Font.ColorIndex = 2
Columns(1).Font.Color = RGB(0, 0, 0)
End Sub
注意点
- VBEの画面でF8を押していくと、どこの色が変わるのかわかるようにしてあります。
- 数値は変更してください。



コメント