+ Reply to Thread
Results 1 to 17 of 17

VBA expression to insert pagebreak

Hybrid View

  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))


    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Range("AA" & Range("AA" & i + 1).Value)
    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
    2010, 2019
    Posts
    40,689
    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))


    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Range("AA" & Range("AA" & i + 1).Value)
    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
    2010, 2019
    Posts
    40,689
    Maybe like this:
        Dim cell    As Range
    
        For Each cell In Range("AA2:AA6")
            If IsNumeric(cell.Value) Then
                ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Rows(cell.Value)
            End If
        Next cell

  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 !!!

+ 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