特定の列のデータが変わったら改ページして印刷する
 サンプルマクロは、特定の列のデータが変わるのを改ページのタイミングにして
印刷または印刷プレビューを表示しています。
 アクティブシートのA列に入力されているデータを判断していますが、1行目を
各ページの上端に常に表示する行としています。

Sub Sample()

    Dim i    As Integer
    Dim row1 As Integer
    Dim fd   As String
    Dim fd_s As String

    With ActiveSheet
        .PageSetup.PrintTitleRows = "$1:$1"  ' タイトル
        i = 2
        row1 = i
        fd = Left(Cells(i, 1), 1)

        Do

            Do
                fd_s = fd
                i = i + 1
                fd = Left(Cells(i, 1), 1)
            Loop Until fd <> fd_s

        .PageSetup.PrintArea = Format(row1) & ":" & Format(i - 1)
        
        .PrintPreview
      ' .PrintOut

        row1 = i

        Loop Until fd = ""

        .PageSetup.PrintArea = False
        .PageSetup.PrintTitleRows = False

    End With

End Sub

Excel97



戻る


Excel Word Access VBA! モーグ