B10B.表示様式の修正

集計表のセル幅、セル高さ、文字位置、セルの着色などについて説明する。

マクロは次のとおり。


'セル幅を設定

Cells(1, 1).ColumnWidth = 40

'セル幅を一括設定

Range(Cells(2, 1), Cells(NY1 - 1, 1)).Select

Selection.ColumnWidth = 14

'セル高さを設定

Cells(1, 1).RowHeight = 42

'セル高さを一括設定

Range(Cells(2, 1), Cells(NY1 - 1, 1)).Select

Selection.RowHeight = 42

'文字位置を設定

Range(Cells(2, 1), Cells(NY1, 1)).Select

With Selection

.HorizontalAlignment = xlGeneral

.VerticalAlignment = xlTop

.WrapText = True

End With

※パラメータは、xlGeneral、xlTop、xlCenter、xlBottom、xlLeft、xlRightなどから選択する。

'集計表の下2〜4行のA列の文字列を折返しなしに設定

Range(Cells(NY2 + 2, 1), Cells(NY2 + 4, 1)).Select

With Selection

.HorizontalAlignment = xlLeft

.WrapText = False

End With

'セルを着色

Cells(y, x).Interior.Color = RGB(250, 250, 100) '黄色に着色

Cells(y, x).Interior.Color = RGB(200, 255, 200) 'うす緑色に設定

Cells(y, x).Interior.Color = RGB(150, 250, 100) '濃緑色に着色

'書体を設定

Range(Cells(y, 1), Cells(y, 3)).Select

With Selection

.Font.Bold = True 'ボールドに設定

.Font.Color = RGB(255, 0, 0) '文字を赤色に設定

.Interior.Color = RGB(250, 250, 100) 'セルを黄色に着色

End With

'表全体に罫線を設定

Range(Cells(1, 1), Cells(NY2, NX2)).Borders.LineStyle = xlContinuous

'小数点以下なしに設定

Columns(3).Select

Selection.NumberFormatLocal = "0_ "

'小数点以下1位に設定

Columns(3).Select

Selection.NumberFormatLocal = "0.0_ "

'三桁区切りに設定

Columns(3).select

Selection.NumberFormatLocal = "#,##0_ "