+ Reply to Thread
Results 1 to 8 of 8

Print Filters using Macros

  1. #1
    Registered User
    Join Date
    11-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    7

    Print Filters using Macros

    Hello Everyone,

    I'm new to macros but want to use it to make my work easier!
    I'm working with Excel 2013 and I build reports for work. Right now I have a spreadsheet with 3 columns and 660 rows. The spreadsheet is caseloads so column A has Caseworkers, Column B is clients, and Column C is task due.

    I'm trying to use macro to automatically print each caseworkers caseload out. I have 57 different caseworkers that comprise Column A
    I used the record Macro function to get this code but I don't want to copy and paste this code 57 times and put in each caseworkers name. Any ideas?
    Thanks
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 11-02-2016 at 03:34 PM. Reason: Added Code Tags

  2. #2
    Registered User
    Join Date
    11-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    7

    Re: Print Filters using Macros

    Essentially, I would like excel to auto filter Column A and print out each caseworkers caseload

  3. #3
    Registered User
    Join Date
    11-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    7

    Re: Print Filters using Macros

    So I used this code:
    Sub Macro2()

    Dim noDupes As New Collection
    Dim rw As Long
    Dim itm As Variant
    Selection.AutoFilter Field:=1
    rw = ActiveSheet.AutoFilter.Range.Row
    For Each cell In ActiveSheet.AutoFilter.Range.Columns(1).Cells
    If cell.Row <> rw Then
    On Error Resume Next
    noDupes.Add cell.Value, cell.Text
    On Error GoTo 0
    End If
    Next
    For Each itm In noDupes
    Selection.AutoFilter Field:=1, Criteria1:=itm
    ActiveSheet.AutoFilter.Range.PrintOut
    Next

    End Sub


    It worked but started printing tons of blanks after it.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,925

    Re: Print Filters using Macros

    Here is how I would do it. First use a pivot table to get a unique_listing of each person's name. Putting the person's name in the row header and removing the Grand Total should do this. It has the side advantage of putting them in alphabetical order.

    Then overlay the pivot table results with a named dynamic range. Sounds scary, but it isn't. Here are the full details on how to do it: http://www.utteraccess.com/wiki/inde...Dynamic_Ranges

    I will assume that the pivot table results are on sheet 1 in column A and the first name is in cell A4

    Here's how do to it in your case: Go to the page with the pivot results. Go to Formulas -> Name Manager. Click New. Type in "Worker_Names" (without the quotes) in the name box. In the refers to box type =Offset( and then click on the first value in the pivot table. Intellisense will fill in the sheet name and the cell selected.

    So it will look like =OFFSET(Sheet1!$A$4 so far. Then Type ,0,0,Counta( and select all of column A)

    Now it looks like =OFFSET(Sheet1!$A$4,0,0,Counta(Sheet1!$A:$A.

    Close the parenthesis and type -1,1)

    So the command now looks like =OFFSET(Sheet1!$A$4,0,0,Counta(Sheet1!$A:$A)-1,1)

    What this says is go to cell A4, go down zero rows and right zero columns and return a range COUNTA(A:A)-1 rows deep and 1 column wide. The reason for the minus 1 is we don't want to count the headers.

    Then the following code should work
    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  5. #5
    Registered User
    Join Date
    11-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    7
    My code is working but after it prints each caseworkers caseload it tries to print a thousand blank pages. Not sure what part of the code is causing that.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,925

    Re: Print Filters using Macros

    Makes me wonder if there is something wrong with the Print Range. It may not be a row issue, but it might also be a column issue. Try clearing the print range to see what you get

  7. #7
    Registered User
    Join Date
    11-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    7

    Re: Print Filters using Macros

    It's still doing it. Would it have to do with Blanks being a filtered item? I'm not sure how to remove them if it is.

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,925

    Re: Print Filters using Macros

    This is as far as I can take it without actually having the file.

+ 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. Filters Based on Selection (Macros)
    By kishoremcp in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-21-2015, 04:23 AM
  2. Change filters and print based off of a list
    By Pergo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2013, 04:15 PM
  3. Excel 2007 : Excel VBA - filters and macros
    By alannoble in forum Excel General
    Replies: 1
    Last Post: 01-08-2012, 04:36 PM
  4. Macros for selecting filters on a pivot table
    By lizardd18 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-05-2011, 06:46 AM
  5. Advanced Filters & Macros
    By Zan03 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2010, 05:37 PM
  6. Filters and Macros
    By praveen_khm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2006, 02:10 PM
  7. [SOLVED] filters and macros
    By Martin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2005, 06:05 AM

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