Consulting

Results 1 to 6 of 6

Thread: auto set page break to last row with data

  1. #1
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location

    auto set page break to last row with data

    I have a sheet with data from columns a to v and row 2 to variable end.

    If on a specific sheet ("3 Summary") I would like to automatically set the horizontal bage break to the last row which could be row 200 to 300.

    If been trying to use many codes I've come across but it does not seem to work. Any help is appreciated.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I don't know if you want the break before or after the last cell: this is for before
    [VBA]Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim c As Range
    If Sh.Name = "3 Summary" Then
    Set c = Range("A:V").Find("*", searchorder:=xlRows, searchdirection:=xlPrevious)
    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c 'or Before:=c.Offset(1)
    End If
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    Hi mdmackillop..

    Sorry for delayed reply, but this does not seem to work for me. I get no movement of the pagebreaks what so ever.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a sample workbook and indicate where the page breaks should be?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    It would be difficult to post the workbook. I tested your code on a blank workbook and it does work.

    With my workbook I have formulas in column a and column b. column a if iserror give value ""

    Would that be a factor?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I cannot see that it would.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •