Consulting

Results 1 to 18 of 18

Thread: Help with a VBA Print Range Code Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular Jack58's Avatar
    Joined
    May 2004
    Location
    MN
    Posts
    30
    Location

    Help with a VBA Print Range Code Problem

    I am using the code listed below to automatically set my print ranges on my reports. The problem I am having is that if the document has no page breaks, the code works great, however if the report is Sub-Totaled and placing a page break in the document the code below will only print the first page.

    Any example, I have a document that have information for Buyers 1 through 10. I want to have a separate page for each buyer, so I Subtotal by Buyer and Check ?Page Break Between Groups?, again when I do the code will only print the first page, I need it to print the entire range of the document.

    Sub SetPrintRanges(StartCell As String) 
    Dim i As Integer 
    'Dim StartCell As String 
    Dim CheckColumn As Integer 
    'StartCell = "A12" 
    For i = 1 To Sheets.Count 
        CheckColumn = 0 
        Sheets(i).Select 
        Range(StartCell).Select 
        Do Until CheckColumn = 4 
             If ActiveCell.Value = vbNullString Then 
                 CheckColumn = CheckColumn + 1 
             Else 
                CheckColumn = 0 
            End If 
            ActiveCell.Offset(0, 1).Select 
        Loop 
        ActiveCell.Offset(0, -5).Select 
        Do Until ActiveCell.Value = vbNullString 
            ActiveCell.Offset(1, 0).Select 
        Loop 
        Worksheets(i).PageSetup.PrintArea = StartCell & ":" & Chr(64 + ActiveCell.Column) _ 
        & CStr(ActiveCell.Row - 1) 
        Range(StartCell).Select 
    Next i 
    End Sub

    Hope someone can help me out here.

    Thanks

    Jack
    Last edited by Aussiebear; 04-29-2023 at 05:28 PM. Reason: Adjusted the code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •