+ Reply to Thread
Results 1 to 5 of 5

Add page break after every 48th rows + border after last row on page

  1. #1
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Add page break after every 48th rows + border after last row on page

    Hello all,

    Since 3 hours I am trying to do a small macro that will add a page break after every 48th row and a border after the last row in page, but it seems that it just doesn't work...

    I also tried to add the page break manually (macro recorder)

    ActiveSheet.ResetAllPageBreaks
    Set ActiveSheet.HPageBreaks(1).location = Range("A48")
    Set ActiveSheet.HPageBreaks(2).location = Range("A96")
    Set ActiveSheet.HPageBreaks(3).location = Range("A144")

    but since my number of pages are not always the same, it gives me an error when the range with data is shorter then the row number on vba...

    Any chance you can help?
    Last edited by lofgren; 03-18-2021 at 02:52 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Add page break after every 48th rows + border after last row on page

    hi,

    this does the trick
    Please Login or Register  to view this content.

    Select you print area and run the code
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  3. #3
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Re: Add page break after every 48th rows + border after last row on page

    Hello Joske920,

    I have a "Runtime Error "5": Invalid procedure call or argument" error at this line:

    PrintArea = Mid(PrintArea, 2, Len(PrintArea) - 1)

  4. #4
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: Add page break after every 48th rows + border after last row on page

    Can you debug code?
    go to VBE and set your cursor inside the Sub SetPagebreak()
    now press F8
    The yellow row will apear now press F8 again to go trough the code untill the error

    What is the contents of the variable PrintArea? you can find it in local variables section or move your mouse cursor over the variable word

  5. #5
    Forum Contributor
    Join Date
    10-06-2017
    Location
    Europe
    MS-Off Ver
    2013
    Posts
    123

    Re: Add page break after every 48th rows + border after last row on page

    Everything is working just fine now. It was something I did wrong I think...
    Thank you very much Joske920

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding border at first page break
    By maym in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2018, 06:15 AM
  2. [SOLVED] Border Line at Page Break
    By jtmeunier in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-26-2013, 07:44 PM
  3. Page break border issue
    By chaddug in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-16-2013, 11:34 AM
  4. [SOLVED] Page Layout (Page Break Preview) is not working with hidden rows in excel.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2013, 03:32 AM
  5. Border In Each Page Break
    By dccdvb in forum Excel General
    Replies: 9
    Last Post: 06-10-2009, 11:10 PM
  6. [SOLVED] Conditional page break if merged rows won't fit on the page.
    By zbprtal in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2006, 04:00 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1