+ Reply to Thread
Results 1 to 12 of 12

Print specific number of filtered records

Hybrid View

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Print specific number of filtered records

    Hello everybody
    I have filtered a range according to specific conditions .. The results are more that 100 rows which are visible.
    I want to determine 25 record to be printed at every time .. the print will be subsequent
    Another point in one of the columns ("ColumnF") I need to add a row to sum the values for these 25 record ..
    I know it may be difficult but I will try with your help and I'm sure we can fulfill this target

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Print specific number of filtered records

    So to level the understanding of the quest . You want to print 4 pages subtotaling each and totaling the report?
    Could you facilitate a sample (not sensitive data) ?

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    Thanks for quick reply Mr. rcm
    Here's a sample .. I put the last row to get the total .. Just last point to print every 25 person and their total ..
    I have a code in the attachment
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    Can anyone help me with that topic?

  5. #5
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Print specific number of filtered records

    Maybe an idea you can adapt ?

    Added a sheet and copied the filtered data for manipulation.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    Thanks a lot Mr. NoSparks

    Great idea .. Just last point >> to get the totals for every printed sheet

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    Thanks a lot
    I could add this line at the last loop
    .Cells(i, 14).Formula = "=SUBTOTAL(109,N3:N" & i - 1 & ")"
    Thanks again for this great help

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    I failed at some parts to do that ...In case of many pages it doesn't succeed ..
    Hope to put the subtotals formulas for every page

  9. #9
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Print specific number of filtered records

    How about this ?
        ' sheet to print
        With Sheet2
            .Select
            .Cells(1, 1).Select '<~~ de-selects the copied range
            LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
            .Range(Cells(LastRow, 3), Cells(LastRow, 33)).ClearContents
            
            For i = 28 To .UsedRange.Rows.Count Step 25
                .Cells(i, 1).EntireRow.Insert   '<~~ row for subtotal
                .Cells(i, 14).Formula = "=SUBTOTAL(109,N3:N" & i - 1 & ")"
                .HPageBreaks.Add Before:=Rows(i + 1)
            Next i
            
            'formula for last row
            LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
            .Cells(LastRow, 14).Formula = "=SUBTOTAL(109,N3:N" & LastRow - 1 & ")"
        End With
    I've never used subtotal and was surprised they could go in the same column and not be included in the next subtotal. Learn something every day.

    I now realize a short coming of this For-Next loop. The .usedrange.rows.count is determined prior to any rows being added so if your printout exceeds 25 pages things will not be right. Should probably be changed to a Do-While loop.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    Thanks for offering help
    I need to add a formula for each page >>
    After applying your great code I got two pages
    In N28 I got this formula
    =SUBTOTAL(109,N3:N27)
    And that's right ..
    But in N45 I got this
    =SUBTOTAL(109,N3:N44)
    And this is not correct . I want it to be like that
    =SUBTOTAL(109,N29:N44)
    I hope it is clear now

  11. #11
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    190

    Re: Print specific number of filtered records

    My misunderstanding, you're looking for the sum of each printed page only.
    Also corrects number of records on each page, there were only 24 after page 1.
    Hope this works.
    Option Explicit
    
    Sub PrintSpecfic()
        Dim strCriteria1 As String, strCriteria2 As String
        Dim X As Long, LastRow As Long, StartSum As Long
        Dim i As Integer
        
        strCriteria1 = Sheet1.Range("AH1").Value
        strCriteria2 = Sheet1.Range("AI1").Value
        
        ' clear print sheet
        With Sheet2
            .Select
            .UsedRange.Delete
            .Cells.PageBreak = xlPageBreakNone
            .Cells(1, 1).Select     '<~~ where paste takes place
        End With
        
        ' filter and copy
        On Error Resume Next
        With Sheet1
            .Select
            .AutoFilterMode = False
            .Range("A2:AI2").AutoFilter Field:=34, Criteria1:=strCriteria1
            .Range("A2:AI2").AutoFilter Field:=35, Criteria1:=strCriteria2
            ' Copy relevant range
            .Range("A1:AG" & .Cells(Rows.Count, "B").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy
            Sheet2.Paste
            Application.CutCopyMode = False
            .AutoFilterMode = False
        End With
        
        ' sheet to print
        With Sheet2
            .Select
            .Cells(1, 1).Select '<~~ de-selects the copied range
            LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
            .Range(Cells(LastRow, 3), Cells(LastRow, 33)).ClearContents
            
            StartSum = 3
            i = 28  '<~~ first row needing inserted
            Do While i < .UsedRange.Rows.Count
                .Cells(i, 1).EntireRow.Insert   '<~~ row for formulas
                .Cells(i, 14).Formula = "=SUM(N" & StartSum & ":N" & i - 1 & ")"
                .HPageBreaks.Add Before:=Rows(i + 1)
                StartSum = i + 1
                i = i + 26
            Loop
    
            'formula for last row
            LastRow = .Cells(Rows.Count, "B").End(xlUp).Row
            .Cells(LastRow, 14).Formula = "=SUM(N" & StartSum & ":N" & LastRow - 1 & ")"
        End With
        'ActiveWindow.SelectedSheets.PrintOut Copies:=1
    End Sub

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Print specific number of filtered records

    Now it is perfect
    Thanks a lot for this great help
    Thank you very much. You are awesome

+ 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. Automative Macro Print All Records in a Filtered List
    By kthumm11 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-16-2012, 11:55 AM
  2. Need Macro to insert a Specific number of Rows (in Filtered list)
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2012, 08:05 PM
  3. Print specific number of pages?
    By deeppurple247 in forum Excel General
    Replies: 1
    Last Post: 01-26-2007, 04:19 PM
  4. Can you print a specific number of pages?
    By deeppurple247 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2007, 02:17 PM
  5. Number of records by Month that meet a specific requirement
    By Keith Brown in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-05-2005, 02:06 PM

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