+ Reply to Thread
Results 1 to 4 of 4

Excel VBA conditional insert of page breaks

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Excel VBA conditional insert of page breaks

    I have a form that is changing all the time according to my "Filling form" where user is filling in information. Then I have "Print version" sheet for autoformatting and printing to .pdf/.xls. In "Print version" I have paragraphs of text in column "C". Some cells with text of column "C" are too long so I am wrapping them with my VBA (.WrapText = True). I want to make conditional page breaks that will read through my Print Area and insert page breaks after each empty row after each paragraph that is not fitting to page compleatly. My VBA code below is working fine except for text being wrapped. If I remove all cells with "Wrap text" command each row have some constant height, let's say 15 so I know amount of rows could be fitted on the page and set my "PgSize = 91" or whatever it is but if I wrap text I don't know how many rows can be fitted on the page. So the problem is: If I set "PgSize = 91" in "Sub FitGroupsToPage()" (that's an amount of rows could be fitted to each page) to 91 and don't wrap my text then everything works fine. However text must be wrapped to fit to my page vertically. Then there is not 91 rows but less, depending on the length of the text in wrapped cells. So number 91 is dynamic each time after hiding and wrapping "Sub FitMyTextPlease()" and "Sub HideMyEmptyRows()" and "Sub SetPrintArea()". Number of rows can also be different on every page (depending of how much text there are in wrapped cells on each page). Any ideas of how this issue can be fixed or maybe suggest some other way of approaching this?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mrwadi; 10-17-2018 at 05:50 AM.

  2. #2
    Registered User
    Join Date
    11-02-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Excel VBA conditional insert of page breaks

    Problem is that paragraphs are not every 10th or 15th or 18th row. There are can be different amount of paragraphs and rows in each paragraph. They always have a "heading" so maybe it can help somehow. Bold text with heading and then paragraph itself. This complete "block" should be on one page and if it doesn't fit to this page then VBA code should move it to the next page.
    Attached Images Attached Images

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA conditional insert of page breaks

    Try something like this. Adjust the 800 to the total height of standard rows you can fit on one page.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 10-17-2018 at 10:37 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    11-02-2012
    Location
    Germany
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Excel VBA conditional insert of page breaks

    Quote Originally Posted by AlphaFrog View Post
    Try something like this. Adjust the 800 to the total height of standard rows you can fit on one page.

    Please Login or Register  to view this content.
    Thank you for you effort! However I can't get it work for some reason. Please see file attached file to this message. Maybe it is possible for you to try it straight in my file?

    I have already came up with almost working code. Please see this message attachment. It works if you don't wrap the text on the page.
    Please Login or Register  to view this content.
    However if you set
    Please Login or Register  to view this content.
    in first Macro. It is not working as
    Please Login or Register  to view this content.
    is not 91 anymore (or 51 in my case).
    Attached Files Attached Files

+ 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. Insert Page Breaks
    By salloush in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2018, 07:13 PM
  2. Clear all page breaks, then insert new breaks at change in data
    By Alex0929 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2014, 03:12 PM
  3. Insert header , hide rows and insert page breaks
    By dwx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2013, 10:10 AM
  4. Insert header , hide rows and insert page breaks
    By dwx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-15-2013, 03:28 AM
  5. Replies: 7
    Last Post: 04-29-2013, 08:38 PM
  6. Insert Page Breaks code different in Excel 2007 and 2010?
    By Iswarya in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-21-2010, 08:59 AM
  7. [SOLVED] Auto insert page breaks in Excel, based on a sort of numbers
    By peterc89 in forum Excel General
    Replies: 0
    Last Post: 11-09-2005, 11:45 AM

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