跳到主要內容

如何在Excel中顯示/顯示自動篩選條件?

自動篩選功能對Excel用戶來說是一項有用的功能,有時,我們會應用自動篩選功能以多種條件篩選數據並將文件發送給其他人。 在這種情況下,如果其他用戶想知道您的過濾條件,他們怎麼辦?

使用用戶定義的功能在工作表中顯示/顯示自動過濾條件

使用VBA代碼在工作表中顯示/顯示自動篩選條件

使用Kutools for Excel在工作表中顯示/顯示自動過濾條件 好主意3


使用用戶定義的功能在工作表中顯示/顯示自動過濾條件

假設您已按照某些條件過濾了以下數據,請參見屏幕截圖:

文檔顯示過濾條件 1

現在,我可以創建一個用戶定義函數,以將過濾條件顯示到單元格中,請執行以下步驟:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic應用程序窗口.

2。 點擊 插入 > 模塊,然後將以下宏粘貼到 模塊窗口:

Function AutoFilter_Criteria(Rng As Range) As String
'Updateby20140220
Dim str1 As String, str2 As String
Application.Volatile
With Rng.Parent.AutoFilter
    With .Filters(Rng.Column - .Range.Column + 1)
        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
End With
AutoFilter_Criteria = UCase(Rng) & ": " & str1 & str2
End Function

3. 然後保存並關閉此代碼,在空白行的空白單元格(例如單元格A1)中,輸入以下公式 = AutoFilter_Criteria(A4) (A4 是已過濾數據的標題單元格),請參見屏幕截圖:

文檔顯示過濾條件 1

4。 然後按 Enter 鍵,然後選擇單元格A1,將填充手柄拖到您需要包含此公式的右側單元格中,並且所有條件都已顯示在這些單元格中,請參見屏幕截圖:

文檔顯示過濾條件 1

備註:如果一列中有兩個以上標準,則此用戶定義函數將無法給出正確的結果。


使用VBA代碼在工作表中顯示/顯示自動篩選條件

在這裡,我還可以討論一個有趣的VBA代碼,它可以幫助您在工作簿的單元格中顯示過濾條件。

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic應用程序窗口.

2。 點擊 插入 > 模塊,然後將以下宏粘貼到 模塊窗口:

VBA代碼:在工作表中顯示自動篩選條件

Sub ShowAutoFilterCriteria()
'Updateby20140219
Dim xFilter As AutoFilter
Dim TargetFilter As Filter
Dim TargetField As String
Dim xOut As String
Dim OutRng As Range
If ActiveSheet.AutoFilterMode = False Then
    Application.StatusBar = False
    Exit Sub
End If
xTitleId = "KutoolsforExcel"
Set OutRng = Application.Selection
Set OutRng = Application.InputBox("Cell", xTitleId, OutRng.Address, Type:=8)
Set xFilter = ActiveSheet.AutoFilter
For i = 1 To xFilter.Filters.Count
   TargetField = xFilter.Range.Cells(1, i).Value
   Set TargetFilter = xFilter.Filters(i)
   If TargetFilter.On Then
        On Error GoTo OutNext
        xOut = xOut & TargetField & TargetFilter.Criteria1
        Select Case TargetFilter.Operator
            Case xlAnd
            xOut = xOut & " And " & TargetField & TargetFilter.Criteria2
            Case xlOr
            xOut = xOut & " Or " & TargetField & TargetFilter.Criteria2
            Case xlBottom10Items
            xOut = xOut & " (bottom 10 items)"
            Case xlBottom10Percent
            xOut = xOut & " (bottom 10%)"
            Case xlTop10Items
            xOut = xOut & " (top 10 items)"
            Case xlTop10Percent
            xOut = xOut & " (top 10%)"
        End Select
    End If
Next
OutRng.Value = xOut
OutNext:
xOut = xOut & TargetField & "= Multiple Filters"
ErrorHandler:
Resume Next
End Sub

3。 然後按 F5 要運行此代碼的關鍵,將彈出一個提示框,讓您選擇一個空白單元格放置條件,請參見屏幕截圖:

文檔顯示過濾條件 1

4。 然後點擊 OK,所有條件已顯示在所選單元格中,如下所示:

文檔顯示過濾條件 1

注意:

使用此VBA代碼,如果您的標准在一列中超過兩個,則不會顯示詳細的過濾條件,而是顯示如下:

文檔顯示過濾條件 1


使用Kutools for Excel在工作表中顯示/顯示自動過濾條件

如果你有 Excel的Kutools 安裝後,可以應用它 超級濾鏡 過濾數據的功能,同時您可以隨時查看過濾條件。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

免費安裝 Kutools for Excel,請執行以下操作:

1。 點擊 Kutools 加 > 超級濾鏡 顯示 超級濾鏡 功能。 看截圖:
doc超級過濾器1

2。 在裡面 超級濾鏡 窗格中單擊 文檔選擇按鈕 選擇要過濾的數據范圍,然後選中“指定”複選框以固定過濾範圍。 看截圖:
doc超級過濾器2

3。 在裡面 超級濾鏡 窗格中,單擊過濾器組中的一行,然後根據需要在下拉列表中指定過濾條件,然後單擊“確定”以完成條件設置。 看截圖:
doc超級過濾器2

4。 點擊 篩選,並且所選數據已按條件過濾,與此同時,您可以查看過濾條件顯示在 超級濾鏡 窗格。 看截圖:
doc超級過濾器3

注意:您可以將過濾器條件另存為方案,以備下次使用“超級過濾器”實用程序使用。

1.點擊 保存當前的過濾器設置 按鈕,在彈出的對話框中,輸入過濾器名稱。
doc kutools超級過濾器5

2.下次要使用此文件管理器設置時,請單擊菜單按鈕,然後在以下菜單的子菜單中選擇方案: 打開保存的過濾器設置方案.
doc kutools超級過濾器6


最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Dear Sir, Please see here below mentioned query for your easy understanding. I want to see the result in column E7 when i filter data in column A3 (Column E7) Vendor Name: (column A3) Vendor Name Abdul Aziz Fahad Al Hajri Est Ali-Ahmed-Al-Kanfari Gen. Co. Est. Amtar Al-Watan Const. & Dev. Est. Arab Al-Tamuz for Cont. Est. Arkal Est. for Cont. Danat Al-Rayan Gray Falcon
This comment was minimized by the moderator on the site
Hi, The code for show auto filter criteria in the worksheet works great. As suggested, if there are more than two criteria, I output text saying 'multiple criteria'. However, I'd really like to be able to generate a list of what the multiple criteria are. Is this at all possible? Cheers, Alex
This comment was minimized by the moderator on the site
hi there, thank you for the code, it works like a charm. One thing I have trouble with thouhg - when I select filter criteria the designated cell displays whichever two I had selected. If then I select two different criteria the designated cell content doesn't refresh. It seems stuck at my first filter selection. Is there anythig I can do? Thank you, Wendy
This comment was minimized by the moderator on the site
This code is great and has helped me a lot. I ran into a problem when I tried to select new filter criteria. The cell that displays the filter criteria selected doesnt refresh when I am selecting new criteria. Please help, Thank you, Wendy
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations