Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Vancouver, Canada
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If Statements based on Auto Filter (Excel 2000 SR1)

    I have a sheet which I Auto Filter to print out 7 different reports. I would like to automate this process with a macro...I know how to code the Auto Filtering...what I need help with is that I need the title of the report to change based on what the filter is.

    Can anyone help me?

    Thanks in advance,

    Christa

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: If Statements based on Auto Filter (Excel 2000 SR1)

    Using the previous <!post=xl,117315>Post 117315<!/post>, here is a very simple example:

    Sub Filter_P_Print()
    Worksheets("Data").Activate
    With ActiveSheet
    .UsedRange.AutoFilter Field:=1, Criteria1:="P" 'Filter for P
    .PageSetup.CenterHeader = "P" ' Set Title as "P"
    .PrintOut Copies:=1 'Print it out
    ' repeat other filters, titles and print as needed
    .UsedRange.AutoFilter 'Autofilter off
    End With
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: If Statements based on Auto Filter (Excel 2000 SR1)

    Here's a better example, assuming P, N and O are being filtered for, though it won't win any awards:

    Sub Filter_Each_Print()
    Dim arvList As Variant, arvTitle As Variant
    Dim intC As Integer
    ' next line sets up titles - must match item-for-item in the 'For Each' Line
    arvTitle = Array("P Stuff", "N Stuff", "Other Stuff")
    Worksheets("Data").Activate
    For Each arvList In Array("P", "N", "O") 'set items to filter on
    With ActiveSheet
    .UsedRange.AutoFilter Field:=1, Criteria1:=arvList ' Filter for the items in the Array
    ' next line sets CenterHeader as the corresponding item in the Titles Array
    .PageSetup.CenterHeader = arvTitle(intC)
    .PrintOut Copies:=1 ' Print
    intC = intC + 1 'Increment the counter
    End With
    Next arvList
    ActiveSheet.UsedRange.AutoFilter ' turn Filter off
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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