开发者

Excel start new page printing when column b change value

Are there any functions or methods that start a new page print开发者_运维技巧ing when column b is changed?

For example, as column b changes value from David to Robert start a new page.


I'm not sure what you mean but the following code will print the worksheet when user changes a cell of column B

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 2 And Target.Columns.Count = 1 Then
        ThisWorkbook.ActiveSheet.PrintOut
    End If
End Sub

Edit After Comment

So this is what you need:

Sub PaginateBasedOnColB()
    Dim lngRowsCount As Long
    Dim lngCounter As Long

    lngRowsCount = ThisWorkbook.ActiveSheet.UsedRange.Rows.Count

    MsgBox lngRowsCount

    For lngCounter = 1 To lngRowsCount

        If ThisWorkbook.ActiveSheet.Cells(lngCounter, 2) <> _
            ThisWorkbook.ActiveSheet.Cells(lngCounter + 1, 2) Then
            ThisWorkbook.ActiveSheet.HPageBreaks.Add (ThisWorkbook.ActiveSheet.Range("B" & lngCounter + 1))
        End If

    Next lngCounter
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜