Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Display the AutoFilter Criteria Applied to a Data Set in a Cell in Excel - UDF


Bookmark and Share

This free Excel UDF (user defined function) allows you display the filter criteria that has been applied to a data set in Excel. This means that it will output, in text, the actual criteria used to filter the data. This allows you to quickly and easily know what criteria you are using to filter your data set.

This is a great function to use if you often filter data, especially if you then disseminate the filtered results to others who might want to know what you used to filter the data. This is also easy to use since you only have to input the cell reference of the header to the filtered data in order to return the criteria for the filter. It is probably best to put this function in a cell directly above the filter header so that it is easy to locate and understand.
Where to install the macro:  Module

UDF to Display the AutoFilter Criteria Applied to a Data Set in a Cell in Excel

Function AUTOFILTERSHOWCRITERIA(Header As Range) As String

Dim strCri1 As String
Dim strCri2 As String

Application.Volatile

With Header.Parent.AutoFilter

With .Filters(Header.Column - .Range.Column + 1)

If Not .On Then Exit Function


strCri1 = .Criteria1

If .Operator = xlAnd Then

strCri2 = " AND " & .Criteria2

ElseIf .Operator = xlOr Then

strCri2 = " OR " & .Criteria2

End If


End With

End With


AutoFilter_Criteria = UCase(Header) & ": " & strCri1 & strCri2

End Function


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Excel Vba: Display Excel Autofilter Criteria. Show Auto Filter Criteria In Excel - Excel

View Content
This topic on Ozgrid provides just what I need, but limited to only 2 criteria - my VBA is not up to extending the code to the ten criteria that I need. Can anyone point me in the right direction please? VB:

Function AutoFilter_Criteria(Header As Range) As String  Dim strCri1 As String, strCri2 As String        Application.Volatile            With Header.Parent.AutoFilter          With .Filters(Header.Column - .Range.Column + 1)                        If Not .On Then Exit Function                                strCri1 = .Criteria1              If .Operator = xlAnd Then                  strCri2 = " AND " & .Criteria2              ElseIf .Operator = xlOr Then                  strCri2 = " OR " & .Criteria2              End If                        End With      End With                AutoFilter_Criteria = UCase(Header) & ": " & strCri1 & strCri2  End Function 


If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines



Display Autofilter Criteria - Excel

View Content
Ok here's my problem:
I have a column of Store Names ie. Wal-Mart, Target, etc.
When I apply the AutoFilter to display all Wal-Marts for example, I want a cell, we'll call it Cell:B4 on a different worksheet within the same workbook to display the name of the store selected in the AutoFilter (Wal-Mart in this example). I need that same cell to change anytime the AutoFilter is changed to another store.

So, Cell:B4 should always display what the filter is set to ie. All; Wal-Mart; Target; or whatever store I choose.

Can anyone help?

Thanks in advance

Display Autofilter Criteria? - Excel

View Content
Hi folks!

I've read the following help thread http://www.ozgrid.com/VBA/autofilter-criteria.htm and it works fine. But it won't work if there are more than 2 filter criteria selected. I suppose, I would have to change it from "xlOR" to "xlFilterValues" and do something with "array". But I don't know how.

Can anyone help?

Thanks!
Nidi

Display More Then 2 Autofilter Criteria - Excel

View Content
Hello!
I'm very new to all the VBA and Macro's.
I have a datasheet (sheet2) with filters, and an overview page (sheet1), where all totals are displayed.
I need to have the the filtercriteria as well (Sheet1), and used the OZGRID page""Display Excel AutoFilter Criteria" to get the code.
I just can't seem to get more then 2 filtercriteria to show. More return with "#Value!"
What do I have to put in the code (and where) to make it show more then 2 filtercriteria?

I've included the workbook, so you can see waht I've done and need.

Micha

Excel 2000: Vba - Autofilter Criteria References A Cell - Excel

View Content
Hello Board

I have a line of code in my macro that is supposed to autofilter a specific column, by selecting >= a certain cell, and

Display Data From Multiple Cell In A Single Cell, Based On Criteria - Excel

View Content
Hello,

I am trying to get data from a range of cells to display in a single cell, based on a criteria. I have a list of job codes, with the names of who worked the job. I want the output to be a table with the job codes on it, that lists each name with a comma separator. I have attached a workbook to give an example.

The raw data will always change, so I cannot use a formula that references specific cells.

How Can I "show All Data" When An Autofilter Is Applied? - Excel

View Content
I have a password protected sheet, the data is autofiltered, I wanted a simple macro to un-filter all the data but levae the AutoFilter buttons intact.

Tried making a macro that memorized my steps:
-unprotect
-remove autofilter
-add autofilter
-reprotect

some reason not working

Is there a simple piece of VBA or something I can add to just have the data become unfiltered but the AutoFilter buttons still there?

Get Value From First Visible Row After Autofilter Applied? - Excel

View Content
Never mind - I got it, courtesy code posted here by Dave Peterson.



Fill Listbox After Autofilter Has Been Applied - Excel

View Content
Hi there,

I'm looking for some code that would allow me to fill a listbox on a userform with the resulting columdata (column D) after the columns to the left have been autofiltered.

Anyone who could be of assistance, please ?

Thanks in advance
Eric

Check If Autofilter Is Applied Or Not (for Single Column) - Excel

View Content
Hey guys!
I need a macro which checks, if there is a certain autofilter criteria setup for a certain column on a different sheet.
Sometimes this sheet has a autofilter applied for the column, sometimes not. I can't simply do something like this (as you propably know):

Code:

If Sheet62.Range("C14:C65000").AutoFilter Field:=1, Criteria1:="Y" Then ...


In fact I wanna check several columns, if there are AutoFilters applied and then warn the user.
Thanks for your help!

Random Tutorials
Goal Seek Feature in Excel
(Intermediate)
Extract Text from Cells - Intermediate Example
(Intermediate)
Introduction to Making Formulas in Excel
(Easy)
AND(), OR(), and IF() Statements/Formulas
(Intermediate)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
How to record a Macro - And what One is
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com