Sub myHeader() With ActiveSheet.PageSetup .LeftHeader = "2012年PV合計" & Chr(10) & _ Format(Application.WorksheetFunction.Sum(Range("C2:C13")), "#,##0") .CenterHeader = "2013年PV合計" & Chr(10) & _ Format(Application.WorksheetFunction.Sum(Range("C14:C25")), "#,##0") End With ActiveWindow.SelectedSheets.PrintPreview End Sub |
Sub myHeader2() Dim i As Long Dim ans1 As Double, ans2 As Double For i = 2 To 13 ans1 = ans1 + Cells(i, 3).Value Next i For i = 14 To 25 ans2 = ans2 + Cells(i, 3).Value Next i With ActiveSheet.PageSetup .LeftHeader = "2012年PV合計" & Chr(10) & Format(ans1, "#,##0") .CenterHeader = "2013年PV合計" & Chr(10) & Format(ans2, "#,##0") End With ActiveWindow.SelectedSheets.PrintPreview End Sub |
よねさんのExcelとWordの使い方|エクセル2013基本講座:目次|ページ番号・ヘッダー/フッター|ヘッダー/フッターに計算結果を表示したい(VBA)