Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Showing Filter Criteria on a Printout.

Showing Filter Criteria on a Printout

Written by Allen Wyatt (last updated March 16, 2022)
This tip applies to Excel 2007, 2010, 2013, and 2016


8

Microsoft Excel includes some great tools that help you filter large data tables to include only the information you want displayed. In effect, the filters allow you to "slice and dice" your data until you get just what you want.

When printing out filtered data, you might want to know what slicing and dicing was done to the original data. There are several ways you can go about displaying your filtering criteria. One simple way is to use the advanced filtering capabilities of Excel, which require that you set up a small criteria table for your data. If the criteria table is made part of what you print, then you can see your filtering criteria quite easily.

If you use AutoFilter, then you need to use a different approach. One such approach is detailed at John Walkenbach's site:

http://j-walk.com/ss/excel/usertips/tip044.htm

This solution uses a user-defined function to return any filtering criteria in use in the current column. The function can be used in a cell in that column to display the criteria. If you are using advanced filtering, then the macro approach is a bit more complex. The following macros (there are two of them in the listing) examine what advanced criteria are in play, and then place the criteria in the left portion of the header.

Sub AddFilterCriteria()
    Dim strCriteria As String

    strCriteria = FilterCriteria()
    If strCriteria = "" Then
        strCriteria = "No Filtering Criteria"
    Else
        strCriteria = "Filter Criteria:" & Chr(10) & strCriteria
    End If

'   add Criteria string to Header/Footer
    With ActiveSheet.PageSetup
        .LeftHeader = strCriteria
    End With
End Sub

Function FilterCriteria() As String
    Dim rngCriteria As Range, col As Range, cel As Range
    Dim strCriteria As String, r As Integer, c As Integer
    Const strCriteriaRange As String = "Criteria"

    FilterCriteria = ""

    On Error Resume Next
    'Set Criteria-Range reference
    Set rngCriteria = Range(strCriteriaRange)
    If Err <> 0 Then Exit Function
    On Error GoTo 0

'   Create Criteria String
    c = 0
    For Each col In rngCriteria.Columns
        c = c + 1     ' CriteriaRange Columns
        r = 1         ' CriteriaRange Rows
        For Each cel In col.Cells
            If r = 1 Then
                strCriteria = strCriteria & "Criteria" _
                  & c & " (" & cel.Value & ") = "
            Else
                strCriteria = strCriteria & "'" & cel.Value & "'"
                If IsEmpty(cel.Offset(1, 0)) Then
                    'Add New row Char if not Last Criteria Column
                    If c < rngCriteria.Columns.Count Then
                        strCriteria = strCriteria & Chr(10)
                    End If
                    Exit For
                End If
                strCriteria = strCriteria & "  "
            End If
            r = r + 1
        Next cel    ' next criteria row
    Next col        ' next criteria column

    FilterCriteria = strCriteria
End Function

To use the macro, just run the AddFilterCriteria macro, after you have your advanced filtering set up. The macro reads the criteria table and puts together the criteria into a string that is placed in the left header.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11649) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Showing Filter Criteria on a Printout.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing the Office Assistant

How to change the Office Assistant character in Word.

Discover More

Getting Rid of Trailing Spaces in Table Cells

If you have tables in your document, there may be trailing spaces within the cells of those tables. This tip provides a ...

Discover More

Deleting the Open Document File

Want to delete the document you are currently viewing? Word doesn't provide a way to do it, but you can use the macro in ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Copying Comments when Filtering

The filtering feature in Excel allows you to quickly copy unique information from one data list to another. If you want ...

Discover More

Skipping Rows when Filling

Using the fill handle is a great way to quickly fill a range of cells with values. Sometimes, however, the way to fill ...

Discover More

Non-PivotTable Slicers and Timelines

When working with a PivotTable, slicers and timelines can make short work of large data sets. This tip looks at all the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 5?

2022-09-06 16:30:47

J. Woolley

The Tip's macro puts the filter criteria in the worksheet's left header. My Excel Toolbox includes the SetHeaderFooter function to put Text in a worksheet's headers or footers; see https://excelribbon.tips.net/T000559_Using_a_Formula_in_a_Footer.html for a complete description. The ListAutoFilters dynamic array function is described in my previous comment below. The following formula will display the 1st auto filter criteria in the left header:
=SetHeaderFooter("head","left",INDEX(ListAutoFilters(,TRUE),3,1))
Change the last argument from 1 to 2 for the 2nd auto filter, for example.
See https://sites.google.com/view/MyExcelToolbox


2022-08-23 16:13:39

J. Woolley

My Excel Toolbox includes the following dynamic array function to list a worksheet's auto filters (Data > Filter):
=ListAutoFilters([Target],[SkipHeader])
It represents a major update of the procedure described at John Walkenbach's site. For details, see my comment here: https://excelribbon.tips.net/T012839_Using_a_Filtered_Value_in_a_Formula.html


2022-08-16 17:26:38

J. Woolley

@Shadeburst
See https://excelribbon.tips.net/T007851_Advanced_Filtering.html#comment-form-hd
The TIp should note that the Advanced Filter dialog normally defines a "Criteria" named range from the contents of the "Criteria range:" text box and an "Extract" named range from the contents of the "Copy to:" text box (if any). These can be viewed with Formulas > Name Manager (Ctrl+F3).


2022-08-16 11:08:18

J. Woolley

Here is a link to the Walkenbach tip: https://web.archive.org/web/20080729232536/http://www.j-walk.com/ss/excel/usertips/tip044.htm


2022-08-15 07:15:45

Shadeburst

This doesn't explain how to set the filtered range that is to be queried.


2017-03-08 11:49:29

Tom Dziubakowski

Note: The J-Walk link doesn't work..... Just thought you would like to know


2016-02-29 10:56:20

Gary Lundblad

What if you want to display the filters used in a pivot table? Will these macros still work?

Thank you!

Gary


2016-02-27 17:34:31

Peter

The link to John Walkenbach's site doesn't work


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.