+ Reply to Thread
Results 1 to 17 of 17

Inserting & Removing Page Breaks

  1. #1
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Inserting & Removing Page Breaks

    Good morning. I'm attempting to add/remove page breaks between ranges so that when the user prints, each range (table) is on it's own individual sheet.

    I've tried recording a macro to accomplish this and this is what I came up with and I'm not sure how to apply it to my AddIHSS code.

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    I'm using the following lines of code to add a new range within the worksheet; there may be one or many of such ranges added to the worksheet.


    Please Login or Register  to view this content.
    So my questions are:

    1) Is adding page breaks my best bet for accomplishing my goal of each range being printed on a single page?
    2) Is it best to write a separate macro for this or add lines to my existing "AddIHSS" code above?

    I appreciate any help you might be able to offer. Thanks.

    Matthew
    Last edited by moosetales; 06-03-2014 at 07:00 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Inserting & Removing Page Breaks

    Hi Matthew,

    You can probably add the page breaks in your existing code. I would suggest finding the row you want for the page break (e.g. 'myRow = r.row' or' myRow = r.row + 3').

    Please Login or Register  to view this content.
    I hope the above helps.

    Lewis

  3. #3
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    Lewis,

    Thanks for getting back to me this morning. I've tried my hand at adding the recommended code to my existing code for the AddIHSS and I keep coming up short (errors). It's likely less about your code and more about my lack of knowledge as to the correct placement of the code. Would you be willing to point me in the right direction as to where you were thinking the recommended code might be placed in my code?

    Also, I'm thinking that if I I reset all page breaks in the worksheet won't I be undoing what I've previously done each time I add a new range? Thanks again for your help.

    Matthew

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting & Removing Page Breaks

    Hi Matthew

    It's a bit difficult to advise you without seeing what your issue is. Please post a copy of the Workbook and explain where you'd like the Page Breaks to appear.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    Lewis & John,

    I know better than to not included a sample of the workbook I'm working on when I post a question.....sorry about that. Here you go. I've highlighted where I'm attempting to insert page breaks with yellow/grid pattern.

    Matthew

    P.S. Password for the sheets is "j" and if the button disappear hit ctrl + r and they will reappear.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Inserting & Removing Page Breaks

    Hi Matthew,

    Your sample workbook was very helpful. Try the following (which places the 'Page Break' after the yellow cross hatching). Changes are in blue:
    Please Login or Register  to view this content.
    The 'Delete' is probably not needed in your application, as you are adding data at the end of the sheet, in this routine.

    Lewis

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting & Removing Page Breaks

    Hi Matthew

    In general the Code will be something like this
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    Lewis,

    Your suggested modifications work great. I'm still running it through it's paces and will let you know how it turns out.

    John,

    I noticed that in your suggestion is "resetting" the page breaks each time the sub runs. Does this prevent extra page breaks from "building up" when new ranges are added and then deleted? Also, I presume the sub routine will need to be called when I'm adding or deleting a new IHSS or CS?

    Thanks guys for offering up suggestions.

    Matthew

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting & Removing Page Breaks

    Hi Matthew

    Best I can suggest is test Lewis' Code, see what happens.
    Does this prevent extra page breaks from "building up" when new ranges are added and then deleted?
    Regarding this, I'd make it part of the Print Routine...reset Page Breaks each time you print
    the sub routine will need to be called when I'm adding or deleting a new IHSS or CS

  10. #10
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    John & Lewis,

    I've attached copies of the workbook, one with Lewis' code (V1.99) and the other with John's code (V2.00). Both appear to be behaving identically and perfectly...I might add. I'll run some real data through the workbooks at let you know how things go.

    Neither of the codes appears to be adding additional page breaks or pages when new ranges are added and old ones are deleted. My quick assessment of the two suggested ways of adding page breaks is:

    If all worksheets have a universal place holder (i.e. "Total Hours") then John's code would only need to be added to the workbook once and it would apply to all worksheets...making the process of adding page breaks very effective and efficient. However, if each worksheet requires unique place holders OR the user only wants page breaks on certain worksheets then Lewis' code would be allow for the individualization that would be required.

    Thanks again.

    Matthew
    Attached Files Attached Files

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting & Removing Page Breaks

    Hi Matthew

    I have no ax to grind regarding which Code you use so do what's most comfortable for you.

    Please be aware, in the Code I provided, in the same Routine, the Search String can be made dependent on the Worksheet Name such that only one routine is required.

  12. #12
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    John,

    Silly me....I counted my chickens before they hatched. When I inserted the code you suggested into my workbook I must have had page breaks already set so I did not notice the glitch. Your code works great when I have only two ranges pasted into each worksheet. Once I add a third, fourth, fifth, range there are no page breaks after the second range, third range, etc.

    Here's how I entered your code into my before print command:

    Please Login or Register  to view this content.
    Did I insert your code incorrectly into my before print command? I've attached a version of my workbook for review. Thanks for weighing in.

    Matthew
    Attached Files Attached Files
    Last edited by moosetales; 06-11-2014 at 08:27 PM.

  13. #13
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    John,

    I just uploaded V2.08 again as I think possibly my previous attempt to upload the form did not work as expected. Thanks.

    Matthew

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting & Removing Page Breaks

    Hi Matthew

    It would appear to me you're doing the "Print Out" first then resetting the "Page Breaks". How does it appear to you?

  15. #15
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    John,

    I see your point of ordering the code to fire in the correct order and I've now tried a couple different variations with the following looking to be the most promising but alas I'm still coming up short:

    Please Login or Register  to view this content.
    How is it the code places a page break between the first and second ranges but then ranges thereafter? Hmmmm. Thanks.

    Matthew

  16. #16
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Inserting & Removing Page Breaks

    Hi John,

    I did some digging and found some code that resembles the code you offered but it is slightly different. I gave it a try and it seems to be doing the trick. I've pasted the new code below. When placed along side the code you offered I cannot for the life of me pick out enough difference between the codes to determine why one works and the other does not. I would value your input as to the differences. Thanks.

    Please Login or Register  to view this content.
    Matthew
    Attached Files Attached Files
    Last edited by moosetales; 06-12-2014 at 08:55 AM.

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting & Removing Page Breaks

    Hi Matthew

    In my Post 7 I have this Line of Code
    Please Login or Register  to view this content.
    In your Post 15 you've changed that line to
    Please Login or Register  to view this content.
    That won't work

+ 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. Removing Existing Page Breaks and Inserting a Page Break every third Total Line
    By Kalvas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-17-2013, 05:12 AM
  2. Removing page breaks
    By Mickmac in forum Excel General
    Replies: 0
    Last Post: 11-10-2011, 12:28 AM
  3. inserting page breaks with a formula
    By LionheartIX in forum Excel General
    Replies: 1
    Last Post: 04-24-2010, 07:03 PM
  4. Inserting Page Breaks
    By chrisnelsonusa1 in forum Excel General
    Replies: 3
    Last Post: 12-09-2005, 05:40 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