文字色の設定


 

Sub test()
    ’  A1を赤字にする(ColorIndex)
  Range("A1").Font.ColorIndex = 3

    ’ A2を青字にする(ColorIndex) Cells(行番号,列番号)形式
  Cells(2,1).Font.ColorIndex =5


    ’ C1を赤字にする(RGB)
  Range("C1").Font.Color =  RGB(255,0,0)

    ’ C2を青字にする(RGB) Cells(行番号,列番号)形式
  Cells(2,3).Font.Color =  RGB(0, 0, 255)

End sub

 

 

解説

 

よく使われる色

vbBlack   黒  1 RGB(0,0,0)
vbWhite  2 RGB(255,255,255)
vbRed 3 RGB(255,0,0)
vbGreen 4 RGB(0,255,0)
vbBlue 5 RGB(0,0,255)
vbYellow 6 RGB(255,255,0)
vbMagenta マゼンタ
(紫)
7 RGB(255,0,255)
vbCyan シアン
(水色)
8 RGB(0,255,255)

 

各Index番号に対応する色(標準)

  •     ColorIndexプロパティとは何か
  •     Colorプロパティとは何か
  •     RGB関数とは何か
などについて、別途時間を作って紹介したいと思います。
 

 

― ― ― ― ― ― ― ― ― ― → Excel VBA基礎入門もくじ へ戻る 

 

関連記事