Results 1 to 12 of 12

Advanced Filtering Data Pulled Form Multiple Worksheets And Displayed On One Sheet

Threaded View

  1. #1
    Registered User
    Join Date
    08-06-2016
    Location
    Oklahoma city, Oklahoma, USA
    MS-Off Ver
    2016
    Posts
    30

    Advanced Filtering Data Pulled Form Multiple Worksheets And Displayed On One Sheet

    Hello,

    First off I dont know much of anything when it comes to programming in Excel with VBA, or programming in general. Ive spent a couple days in my free time trying to gather, search and tinker around with making things work with limited knowledge the way I need it to work. So excuse my poor coding for all you Expert Coders.

    The attached file was originally from someone else, but I need more out of it. I added Base_3 and 4 tabs and messed around with the coding some to get close to what I want. I also added the Base column in the tables and put the value number in the column matching the tab name value.

    So I will try to explain what I need.
    When I am working in Excel, similar to what is seen in the example file, I start out with one tab/worksheet named "Base_1". As I am working, I will create new Tabs and rename them "Base_2 and so on". while I am working and at the end of my work, I would like to use a Data Filtering Table as exampled in the file sheet name "Result". I would like the Filtering table to filter out a name or base value when displayed in the filter options. I could have up to 20 Tabs/worksheets by the end of my work or more or less.

    - If I want to filter out a specific Base value say 2, then I want A) the table to display all the data form worksheet Base_2 with no name filtered and B) with a name filtered.
    - If I dont filter out a specific Base or Name, then I want the filter table to display all data from all worksheets
    - sometimes not all my tab names will be names exactly "Base_1 or Base_2" and so on, sometimes I may add more text such as "Base_3 NW" or "Base_3 SWNW". So if it is possible to have the macro to search for tabs containing Base_# with added wildcard text, then that would be great, if not then I can live with naming a Sheet/tab name exactly.

    What I have now:
    Option Explicit
    Sub Filter()
        Dim ws As Worksheet
            
        For Each ws In ThisWorkbook.Sheets
    
             If Sheets("Result").Range("G2") = "" Then 'this if statement is saying, if no base filtering option is selected, then all data in base tabs will display
        
                If InStr(1, ws.Name, "BASE_1") Then
            
                    Sheets("BASE_1").Range("A1:F1000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("B1:B2"), CopyToRange:=Range("B4:G4"), Unique:=False
            
                    ElseIf InStr(1, ws.Name, "BASE_2") Then 'keep adding this bit of code from elseif to end with for however many more tabs might be created in the future, just change the sheet name in the code
            
                        With Sheets("BASE_2").Range("A1:F1000")
                             .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("B1:B2"), Unique:=False
                             .Resize(.Rows.Count - 1).Offset(1).Copy Range("B4:G4").Offset(Range("B4:G4").CurrentRegion.Rows.Count)
                            'the code ".WorkSheet.ShowAlldata" will not allow Result tab to show all data from all worksheets with no name filtered, removing it works but when filtering a name the base tabs/sheets get filtered aswell
                        End With
                
                     ElseIf InStr(1, ws.Name, "BASE_3") Then
            
                        With Sheets("BASE_3").Range("A1:F1000")
                            .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("B1:B2"), Unique:=False
                            .Resize(.Rows.Count - 1).Offset(1).Copy Range("B4:G4").Offset(Range("B4:G4").CurrentRegion.Rows.Count)
                        
                        End With
                
                     ElseIf InStr(1, ws.Name, "BASE_4") Then
            
                        With Sheets("BASE_4").Range("A1:F1000")
                            .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("B1:B2"), Unique:=False
                            .Resize(.Rows.Count - 1).Offset(1).Copy Range("B4:G4").Offset(Range("B4:G4").CurrentRegion.Rows.Count)
                        
                        End With
                    
                 End If
                 
                End If
        
            
        
             If Sheets("Result").Range("G2") = "1" Then
    
                Sheets("BASE_1").Range("A1:F1000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("B1:B2"), CopyToRange:=Range("B4:G4"), Unique:=False
            
            End If
            
            If Sheets("Result").Range("G2") = "5" Then
    
                Sheets("BASE_5").Range("A1:F1000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("B1:B2"), CopyToRange:=Range("B4:G4"), Unique:=False
            
            End If
            
        Next
            
    End Sub
    Let me know if you need more explanation from me.

    Again thanks to those viewing this and helping out, much appreciation.

    -Brent
    Last edited by disepyon; 07-14-2017 at 04:29 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 08-04-2015, 12:09 PM
  2. Advanced Filtering by ID on other sheet
    By Viktor86HUN in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2014, 03:27 AM
  3. Excel advanced filtering on multiple sheets
    By blind527 in forum Excel General
    Replies: 4
    Last Post: 05-04-2013, 08:56 PM
  4. [SOLVED] Creating a list of data pulled from multiple worksheets
    By mzbreski in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2012, 10:12 PM
  5. Consolidating data from multiple worksheets and filtering based on priority...
    By Spiska01 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-07-2012, 09:19 AM
  6. Advanced filtering with multiple lines in VBA code
    By surfthenet in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2012, 06:56 AM
  7. Advanced Filtering with multiple criteria
    By drumbody in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-16-2007, 08:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1