+ Reply to Thread
Results 1 to 9 of 9

Select visible range and add page break after every 20th visible cell

  1. #1
    Registered User
    Join Date
    03-03-2015
    Location
    USA
    MS-Off Ver
    Office 2013
    Posts
    9

    Select visible range and add page break after every 20th visible cell

    I currenty have a sheet that I want to add page breaks after every 20th visible cell in a specified range. On the sheet there are hidden and visible cells so I need only the visible cells selected in the range. I have been unable to find anything on this specific topic.

  2. #2
    Registered User
    Join Date
    03-03-2015
    Location
    Denver, CO
    MS-Off Ver
    2013
    Posts
    7

    Re: Select visible range and add page break after every 20th visible cell

    Try something like this maybe?

    Please Login or Register  to view this content.
    Last edited by cruelkix; 03-04-2015 at 12:33 AM.

  3. #3
    Registered User
    Join Date
    03-03-2015
    Location
    USA
    MS-Off Ver
    Office 2013
    Posts
    9

    Re: Select visible range and add page break after every 20th visible cell

    That unfortnately does not work. To specify further details... sheet24.range("D7:O109") is the sheet and range I will use. I think I may have to use HPageBreaks.Add in order to not ruin my conditional formating. Thank you for your quick responce!

  4. #4
    Registered User
    Join Date
    03-03-2015
    Location
    Denver, CO
    MS-Off Ver
    2013
    Posts
    7

    Re: Select visible range and add page break after every 20th visible cell

    Oh you meant you want like a real page break for printing the information out?

  5. #5
    Registered User
    Join Date
    03-03-2015
    Location
    USA
    MS-Off Ver
    Office 2013
    Posts
    9

    Re: Select visible range and add page break after every 20th visible cell

    Exactly. I just have been having issues due to cells being hidden in the selected cell ranges.

  6. #6
    Registered User
    Join Date
    03-03-2015
    Location
    Denver, CO
    MS-Off Ver
    2013
    Posts
    7

    Re: Select visible range and add page break after every 20th visible cell

    Here, this worked in a quick test I ran. Just change the range.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-03-2015
    Location
    USA
    MS-Off Ver
    Office 2013
    Posts
    9

    Re: Select visible range and add page break after every 20th visible cell

    That seemed to work slightly better but still not right. I need the print area to always stay at one page. My columns are larger then the standard one page so the print preview screen is cutting them out. Also, the macro seems to be adding a page break after every cell in the visible range. Thank you for all your help with this.

  8. #8
    Registered User
    Join Date
    03-03-2015
    Location
    USA
    MS-Off Ver
    Office 2013
    Posts
    9

    Re: Select visible range and add page break after every 20th visible cell

    Dim i As Integer, j As Integer
    Dim wsh As Worksheet
    Set wsh = Sheet13

    'remove all page breaks
    wsh.ResetAllPageBreaks
    'enable autoajusting
    wsh.PageSetup.Zoom = False
    'set new area
    wsh.PageSetup.PrintArea = "C7:G107"
    'set paper orientation
    wsh.PageSetup.Orientation = xlLandscape
    'add horizontal page break on every 5 row
    For i = 1 To 5 Step 1
    j = j + 1
    wsh.HPageBreaks.Add wsh.Range("A" & i + 1)
    Next i


    wsh.PageSetup.FitToPagesWide = 1
    wsh.PageSetup.FitToPagesTall = j

    Set wsh = Nothing

    End Sub

    I was using something like this before but it was counting my hidden cells.

  9. #9
    Registered User
    Join Date
    03-03-2015
    Location
    USA
    MS-Off Ver
    Office 2013
    Posts
    9

    Re: Select visible range and add page break after every 20th visible cell

    Dim i As Integer, j As Integer
    Dim wsh As Worksheet
    Set wsh = Sheet13

    'remove all page breaks
    wsh.ResetAllPageBreaks
    'enable autoajusting
    wsh.PageSetup.Zoom = False
    'set new area
    wsh.PageSetup.PrintArea = "C7:G107"
    'set paper orientation
    wsh.PageSetup.Orientation = xlLandscape
    'add horizontal page break on every 5 row
    For i = 1 To 5 Step 1
    j = j + 1
    wsh.HPageBreaks.Add wsh.Range("A" & i + 1)
    Next i


    wsh.PageSetup.FitToPagesWide = 1
    wsh.PageSetup.FitToPagesTall = j

    Set wsh = Nothing

    End Sub

    I was using something like this before but it was not counting my hidden cells.

+ 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. Set a range to select all visible cells
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-30-2014, 09:33 PM
  2. [SOLVED] Code to select visible cell range only
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-23-2013, 03:05 AM
  3. Need code to select a cell range that has visible values
    By Big Chris in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-27-2013, 12:18 PM
  4. Select Cell In Center Of Visible Range
    By Spencer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2011, 01:53 PM
  5. Select visible cells within a set range
    By longbow007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-09-2010, 09:10 PM

Tags for this Thread

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