Skip to main content

 How to apply same filter to multiple sheets In Excel?

It may be easy for us to apply the Filter function to filter data in a worksheet, but, sometimes, you may need to filter across multiple worksheets which have common data formatting with the same filter criteria. To filter them one by one will waste lots of time, here, I can introduce an easy way to solve it at once.

Apply same filter to multiple worksheets with VBA code


arrow blue right bubble Apply same filter to multiple worksheets with VBA code

For example, I have four worksheets as following screenshot need to be filtered with the same criteria that the Product = KTE at once.

doc filter multiple sheets 1

There is no direct way to filter data in multiple sheets in Excel, but, the following VBA code can help you to finish this job, please do as follows:

1. Hold down the ALT + F11 keys, then it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Apply same filter to multiple worksheets:

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. And then press F5 key to run this code, all products of KTE have been filtered in all worksheets at once, see screenshot:

doc filter multiple sheets 2

Note: Within above code, in this xWs.Range("A1").AutoFilter 1, "=KTE" script, A1 and =KTE indicates the column and criteria which you want to filter based on, the number 1 is the column number you filtered based on, you can change them to your need. For example, if you want to filter the order greater than 50, you just need to modify this script as this: xWs.Range("B1").AutoFilter 2, ">50".


Filter data by multiple criteria or other specific condition, such as by text length, by case sensitive, etc.

Kutools for Excel’s Super Filter feature is a powerful utility, you can apply this feature to finish the following operations:

  • Filter data with multiple criteria;              Filter data by text length;
  • Filter data by upper / lower case;             Filter date by year / month / Day / week / quarter

doc-super-filter1

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
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