跳到主要內容

 如何在Excel中將同一過濾器應用於多個工作表?

應用“過濾器”功能來過濾工作表中的數據可能很容易,但是有時,您可能需要跨多個工作表進行過濾,這些工作表具有相同的數據格式並具有相同的過濾條件。 逐個過濾它們會浪費很多時間,在這裡,我可以介紹一種簡單的方法來立即解決它。

使用VBA代碼將相同的過濾器應用於多個工作表


箭頭藍色右氣泡 使用VBA代碼將相同的過濾器應用於多個工作表

例如,我有四個工作表,下面的屏幕截圖需要使用與Product = KTE相同的條件進行過濾。

doc過濾多張紙1

沒有直接的方法可以在Excel中過濾多個工作表中的數據,但是下面的VBA代碼可以幫助您完成此工作,請執行以下操作:

1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

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

VBA代碼:將相同的過濾器應用於多個工作表:

Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice
    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("A1").AutoFilter 1, "=KTE"
    Next
End Sub

3。 然後按 F5 是運行此代碼的關鍵,所有工作表中的KTE所有產品均已被過濾掉,請參見屏幕截圖:

doc過濾多張紙2

備註:在上面的代碼中,在此 xWs.Range(“ A1”)。AutoFilter 1,“ = KTE” 腳本, A1= KTE 表示要作為過濾依據的列和條件,數字1為要作為過濾依據的列號,您可以根據需要進行更改。 例如,如果要過濾大於50的訂單,則只需要按以下方式修改此腳本: xWs.Range(“ B1”)。AutoFilter 2,“ >> 50”.


根據多個條件或其他特定條件(例如,文本長度,區分大小寫等)過濾數據。

Excel的Kutools超級濾鏡 該功能是一個功能強大的實用程序,您可以應用此功能來完成以下操作:

  • 使用多個條件過濾數據; 按文本長度過濾數據;
  • 按大小寫過濾數據; 按年/月/日/週/季度過濾日期

文檔超級過濾器1

Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

最佳辦公生產力工具

🤖 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 (48)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Hello, your code works really well. What about if I want to filter more than one cell value. For example: KTE and KTO? thank you for your help
This comment was minimized by the moderator on the site
Hello, your code works really well. What about if I want to filter more than one cell value. For example: KTE and KTO
This comment was minimized by the moderator on the site
Hi,
i have a work book 20+ sheets, and have to filter each sheet in different column but the same number "0 (Zero)" as in the column "P" in the attached image. along with i have to print preview the sheets which i have mentioned. How to di it sir. Each sheet has link with another or several sheets has linked to specific sheet.
This comment was minimized by the moderator on the site
Works a treat, thank you.
Rated 5 out of 5
This comment was minimized by the moderator on the site
Is it possible to use the code to filter where it does not contain a zero.

I have a workbook with sheets up to 20 sometimes, where one column is always the same in each sheet, want to filter out all zeros.

Hope this makes sense.
This comment was minimized by the moderator on the site
Hello, Richard,
To filter the data exclude the zeros, please apply the below vba code:
Note: in the code, in this xWs.Range("C1").AutoFilter 3, "<>0" script, C1 and <>0 indicates the column and criteria which you want to filter based on, the number 3 is the column number you filtered based on, you can change them to your need.
Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice
    Dim xWs As Worksheet
    On Error Resume Next
    For Each xWs In Worksheets
        xWs.Range("c1").AutoFilter 3, "<>0"
    Next
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
I want to use this code to filter on a column across multiple worksheets, the column will always have numbers in it, but I want the auto filter to remove zero values, leaving just minus and plus numbers.

Is this possible?
This comment was minimized by the moderator on the site
I have a spreadsheet with 2 tabs, I want that when I filter one tab, the other respects the filtered items and is also filtered with the same values, how to do that?
This comment was minimized by the moderator on the site
Hello, Fabio,
To solve your problem, you can use the VBA code in this article, and please remeber to change the cell reference and criteria in the code.
Please try again, hope it can help you!
This comment was minimized by the moderator on the site
I am copying and pasting exactly but keep getting "Compile Error: Invalid outside procedure". I have only changed the criteria to match what I need specifically.. below:

Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
xWs.Range("D3").AutoFilter 1, "=Paige"
Next
End Sub
This comment was minimized by the moderator on the site
Hello, Paige,
I have tested your code, and it works well in my workbook.
Could you upload your excel file here, so that we can check where the problem is.
Thank you!
This comment was minimized by the moderator on the site
Amazing work! this macro is great.
This comment was minimized by the moderator on the site
Thank you skyyang Please how do i remove the hidden rows after filtering?
This comment was minimized by the moderator on the site
Hello, Akoma,
To remove all hidden rows after filtering, please apply the below code: (Note: This code will remove all hidden rows in the worksheet, and it will not undo, so you need backup your data.)
Sub DeleteHiddenRows()
Dim sht As Worksheet
Dim LastRow
Set sht = ActiveSheet
LastRow = sht.UsedRange.Rows(sht.UsedRange.Rows.Count).Row
For i = LastRow To 1 Step -1
If Rows(i).Hidden = True Then Rows(i).EntireRow.Delete
Next
End Sub

Please try, hope it can help you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations