Show Table Filter Criteria In Cell

paco999

New Member
Joined
May 3, 2021
Messages
4
Office Version
  1. 2019
Working on UDF to display the filter criteria for a table. UDF would be just above filtered table. Found perfect UDF but only works on normal filters, not table filters. Having trouble adapting it:

Function Show_Criteria(Rng As Range) As String
Dim str1 As String, str2 As String
Dim tbl As ListObject

Application.Volatile

Set tbl = ActiveSheet.ListObjects("mytable")

With tbl.Range.AutoFilter Field:= tbl.Rng.Column

If Not .On Then Exit Function
str1 = .Criteria1
If .Operator = xlAnd Then
str2 = " AND " & .Criteria2
ElseIf .Operator = xlOr Then
str2 = " OR " & .Criteria2
End If
End With
Show_Criteria = UCase(Rng) & ": " & str1 & str2
End Function
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi & welcome to MrExcel.
How about
VBA Code:
Function Show_Criteria(Rng As Range) As String
   Dim str1 As String, str2 As String
   Dim tbl As ListObject
   Application.Volatile
   
   Set tbl = ActiveSheet.ListObjects("Table1")
   
   With tbl.AutoFilter.Filters(Rng.Column)
   
      If Not .On Then Exit Function
      str1 = .Criteria1
      If .Operator = xlAnd Then
         str2 = " AND " & .Criteria2
      ElseIf .Operator = xlOr Then
         str2 = " OR " & .Criteria2
      End If
   End With
   Show_Criteria = UCase(Rng) & ": " & str1 & str2
End Function
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top