+ Reply to Thread
Results 1 to 17 of 17

VBA expression to insert pagebreak

  1. #1
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    VBA expression to insert pagebreak

    I need to learn VBA syntax.
    I have the following line of code and its not working.

    Here's what I need to do.
    I have a list of row numbers in AA2:AA6, so for i =1 to 5
    I want to insert a page break before cell (column AA and Row(#in cell AA2-5))


    Please Login or Register  to view this content.
    Thanks for help in advance.
    modytrane
    Last edited by modytrane; 10-30-2008 at 10:26 AM. Reason: Added code tags as per forum rules

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Code tags, please.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Sorry,

    --------------------------------------------------------------------------------

    I need to learn VBA syntax.
    I have the following line of code and its not working.

    Here's what I need to do.
    I have a list of row numbers in AA2:AA6, so for i =1 to 5
    I want to insert a page break before cell (column AA and Row(#in cell AA2-5))


    Please Login or Register  to view this content.
    Thanks for help in advance.
    modytrane

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Maybe like this:
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    set page breaks

    Thanks,
    It works.
    modytrane.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    modytrane,

    You need to mark this thread as solved if you found a solution

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  7. #7
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Marking Post As solved

    Sorry for my ignorance, but I do remember seeing the instructions for marking the posts. I just can't seem to recall it.
    Please remind me and I'll take care of it.
    Thanks,
    modytrane.

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    1) Click the EDIT button on your first post
    2) Click the GO ADVANCED button
    3) Select SOLVED from the Title dropdown (under the Reason for Editing box)
    4) Click the SAVE CHANGES button

    Note: If it's more than 2 days after your first post, please ask a moderator to mark the thread SOLVED for you.

  9. #9
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    insert page breaks

    Thanks for that info.

    However, I spoke too soon.
    Following code gives me a runtime error '1004'
    Application-Defined or Object-Defined error.


    I am sure its something simple.
    Thanks for all the help I've been getting here.
    In return I have tried to help some users whenever possible.

    Please Login or Register  to view this content.

    modytrane

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    If code errors, please give us a hand and say where, and avoid an unnecessary pair of posts.

    On a guess, add this as the first line:
    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Error "1004'

    Please Login or Register  to view this content.
    The error still shows up at the line "ActiveWindow.SelectedSheets........"

    Thanks for your time.
    modytrane

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    What's the value in all five cells when you run the code?

  13. #13
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Error 1004

    51
    105
    150
    197
    255

    These are the five values in AA2:AA6.

    Sorry, for the delayed response. I was offline.

    Thanks again for helping me resolve this issue.
    modytrane

  14. #14
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Error 1004

    Shg,
    I don't know what's going on, but it seems to be working now.

    One more request, if you don't mind.

    What would be the code to set the print area to A1:M*

    Where * would represent last row used.

    My worksheet length changes often and I would like to be able to set the print area within the same code that you have helped me with.

    Thanks a lot.

    modytrane.

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Hmm. Next try:
    Please Login or Register  to view this content.

  16. #16
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Set Print Area & Insert Pg Breaks

    Shg,
    Thanks so much for your time and effort.
    I also picked up some code from another thread [from VBA Noob].
    Combined the codes and it's working fine.

    Thanks Again,
    modytrane

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You're welcome.

    How about posting your final code for other members, and explaining the changes?

+ 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