| Sub test() For i = 1 To 10 'G,Bの色を指定する。255をi/10ずつ増加させ、変数idxに格納 idx = 255 * i / 10 'セルの色を指定 Cells(i, 2).Interior.Color = RGB(255, idx, idx) Next i End Sub |
ビジネスプロフェッショナルのExcel術 (日経BPムック)
ExcelはVBAを使いこなすことでエンジニアにとって最強の友達に変身します。C++やJavaを習う傍らで、エクセルを思い通りに動かしてみませんか?シンプルな記述をモットーに、できるだけ短いプログラムを紹介します。
| Sub test() For i = 1 To 10 'G,Bの色を指定する。255をi/10ずつ増加させ、変数idxに格納 idx = 255 * i / 10 'セルの色を指定 Cells(i, 2).Interior.Color = RGB(255, idx, idx) Next i End Sub |
| Sub test() Cells(2, 2).Font.Underline = xlUnderlineStyleSingle End Sub |
| Sub test() Cells(2, 2).Font.Underline = xlUnderlineStyleNone End Sub |
| Sub test() Cells(2, 2).Font.Italic = True End Sub |
| Sub test() Cells(2, 2).Font.Italic = False End Sub |
| Sub test() Cells(2, 2).Font.Bold = True End Sub |
| Sub test() Cells(2, 2).Font.Bold = False End Sub |
| Sub test() Cells(5, 2).Font.Color = RGB(255, 0, 0) End Sub |
| Sub test() Range("B2").Interior.Color = 255 End Sub |
| Sub test() Cells(2, 2).Interior.Color = 255 End Sub |