+ Reply to Thread
Results 1 to 16 of 16

Page Breaks when value changes

  1. #1
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Page Breaks when value changes

    Hi all

    I want some code which will automatically insert a page break every time the data changes in a column. In column B- the data is structured as below;

    DOG
    <blank cell>
    <blank cell>
    DOG
    <blank cell>
    DOG
    <blank cell>
    <blank cell>
    CAT
    <blank cell>
    CAT
    <blank cell>
    MOUSE
    <blank cell>
    MOUSE
    MOUSE
    <blank cell>

    Etc

    The code I want would insert the page break every time every time the data changed- but not where there is a blank cell. I hope this makes sense. I realise the blank cells complicate things- the blank cells separating the data cells are there because there is additional;data in columns C,D,E etc

    Many thanks for any help anyone can give me with this problem
    J

  2. #2
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    redjay,
    use the following line to assign the pagebreak were you need it.

    Please Login or Register  to view this content.
    Not quite sure I understand what do you need.
    How do you know were to place the Pagebreaks esactly?

  3. #3
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Re: Page Breaks when value changes

    Hi wizz

    I need the pagebreaks to be inserted automatically wherever there is a change in the data in column B. So in the example, wherever the data changed from DOG to CAT, thats where I need the page break to go....

    J

  4. #4
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    So, in the following case:
    ________________________________
    DOG
    <blank cell>
    DOG
    <blank cell>
    <blank cell>
    CAT
    <blank cell>
    CAT
    ________________________________

    You would need the pagebreak under the last blank cell over CAT or it should be under the las DOG cell (before the blank cell)?

  5. #5
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Re: Page Breaks when value changes

    Under the last blank cell before CAT would be perfect....

  6. #6
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    Then this should do the trick

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    Almost forgot; to make the procedure run on every data change in column B, copy the following procedure inside the code page where you have the data:

    Please Login or Register  to view this content.
    Remember to keep the SetHPageBreaks inside a Module.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Page Breaks when value changes

    You could also do this using the Subtotals feature incidentally. Might take a little bit of clean up afterwards if you didn't want the summary rows, but it's quick and easy otherwise!
    FWIW.
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Re: Page Breaks when value changes

    Hi Wizz

    Im a bit of a newb so might need some more help here.

    when I try to run SetHPageBreaks, I get a 'Subscript out of range' error?

    Thanks for your help so far

    J

  10. #10
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    Hi redJay;
    Wich line is highlighted when the error pops?

  11. #11
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Re: Page Breaks when value changes

    Wizz,

    Its ok, have solved that problem

    One further thing though, can I amend the code so that instead of inserting the page break directly above the change in data- it instead inserts it on the row before that (i.e one row prior to the change in data) ?

    Thanks!

  12. #12
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    for sure; if you dont care if the previous row is blank or nonBlank, then use the following:
    Please Login or Register  to view this content.
    Otherwise, we'll need some more modification. Just let me know.

  13. #13
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Re: Page Breaks when value changes

    Absolutely brilliant!

    Works perfectly. thanks a million

  14. #14
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    Nice to hear that; it was a pleasure!

    Please remember to tag the thread as [SOLVED].

    G.bye

  15. #15
    Registered User
    Join Date
    04-30-2008
    Posts
    16

    Re: Page Breaks when value changes

    Thanks again Wizz

    Can I just ask- is it possible to modify the code so it also puts in a pagebreak immediately after the last data row in column F?

    The trouble is that the worksheets im using this on vary in size so I cannot use the same row number each time.

    Hope u can help one last time!

    J

  16. #16
    Forum Contributor
    Join Date
    08-02-2007
    Location
    Panama & Austria
    MS-Off Ver
    2003 & 2010
    Posts
    186

    Re: Page Breaks when value changes

    Not a Problem.

    Just add the following line just after the end of the loop (Outside the For loop).

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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