今回は、比率の計算と、計算結果にて、文字の色、背景色を付けるようにしました。
【課題】
・客単価を計算してD列に入れる。
・客単価は「売上 ÷ 客数」で計算し、小数以下2桁で表示する。
・罫線を表示する。
【VBA】
Sub 罫線() Dim i As Long Dim lastRow As Long lastRow = Cells(Rows.Count, 1).End(xlUp).row For i = 2 To lastRow Cells(i, 4) = Cells(i, 2) / Cells(i, 3) Next Range(Cells(2, 4), Cells(lastRow, 4)).NumberFormatLocal = "#,##0.00" Range(Cells(1, 1), Cells(lastRow, 4)).Borders.LineStyle = xlContinuous Range(Cells(1, 1), Cells(lastRow, 4)).Borders.Weight = xlHairline Range(Cells(1, 1), Cells(lastRow, 4)).BorderAround Weight:=xlMedium Range(Cells(2, 1), Cells(2, 4)).Borders(xlEdgeTop).Weight = xlThin Range(Cells(1, 2), Cells(lastRow, 2)).Borders(xlEdgeLeft).Weight = xlThin End Sub
簡単な説明
・「Cells(Rows.Count, 1).End(xlUp).row」は以前説明をしたのでこちらを御覧ください
・「For」は、客単価の計算をして設定
・「NumberFormatLocal = "#,##0.00"」は、小数以下2桁表示にする
・罫線の種類は「Borders.LineStyle」にて設定
・「xlContinuous」は、罫線の直線を表す
・罫線の太さは「Borders.Weight」にて設定
・「xlHairline」は、罫線の太さを表し、「極細」を設定
・罫線の外枠は、「BorderAround Weight:」にて設定
・「xlMedium」は、罫線の太さを表し、「中」を設定
・「xlEdgeTop」は、罫線の位置で「上端」
・「xlThin」は、罫線の太さを表し、「細」を設定
・「xlEdgeLeft」は、罫線の位置で「左端」
あなたのお役に立てるなら、コピーして使用してください。
今後も勉強した内容を記載して行きますので、お役に立てるものがあれば使ってください。
VBA開発もしておりますので開発のご要望があればご連絡をください。
VBA開発依頼受付はこちらから
コメントフォーム