+ Reply to Thread
Results 1 to 7 of 7

Applying multiple filter to data using VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Applying multiple filter to data using VBA

    Hi there, hope all is well!

    Is there a way I can apply more than one filter to a data table from cells on another sheet using VBA?

    Picture1.jpg

    So in the above example, if I enter grade1 in cell B1 and 6 in cell B2 on sheet 1, my table on sheet 2 would filter on grade 1 and 6.

    Many Thanks in advance

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,336

    Re: Applying multiple filter to data using VBA

    Not everybody wants to construct your sheet - quicker answers come when you help us to help you.

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Applying multiple filter to data using VBA

    Apologies, I should have attached my workbook.

    I found some code online which allows me to apply a filter on the data table on the same sheet but I can't work out how to apply multiple filters and from sheet 1

    Private Sub Worksheet_Change(ByVal Target As Range)
    
       If Target.Address = Range("E2").Address Then
           Range("A6:d25").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("E1:E2")
       End If
    End Sub
    Please find attached example.

    Many Thanks
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,159

    Re: Applying multiple filter to data using VBA

    If you transpose your criteria so it's like
    Grade Age
    grade1 6

    You can use
        Sheets("Sheet2").Range("A1").CurrentRegion.AdvancedFilter xlFilterInPlace , Sheets("Sheet1").Range("A1:B2")
    Last edited by Fluff13; 10-29-2020 at 01:59 PM.

  5. #5
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Applying multiple filter to data using VBA

    Thanks, sorry if this is a silly question, do i still need to set a target.address ? So on sheet1, if I right click on the tab -> "View Code" and then...

    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Address = Range("A2").Address Then
           Sheets("Sheet2").Range("A1").CurrentRegion.AdvancedFilterxlFilterInPlace , Sheets("Sheet1").Range("A1:B2")
       End If
    End Sub
    Thanks!!

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,159

    Re: Applying multiple filter to data using VBA

    I would use
    If Not Intersect(Target, Range("A2:B2")) Is Nothing Then
    That way it will trigger if you change either A2 or B2

  7. #7
    Registered User
    Join Date
    03-24-2011
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Applying multiple filter to data using VBA

    Awesome, thank you that works now! The only thing I had to add was "CriteriaRange:=" at the criteria section. So its reads...

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A2:C2")) Is Nothing Then
    Sheets("Sheet2").Range("A9").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Sheets("Sheet1").Range("A1:C2")
    End If
    End Sub
    Many Thanks for your help, much appreciated!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA to fill down multiple columns after applying filter
    By kknb0800 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2017, 05:17 PM
  2. Applying a filter on the same Data in Multiple Sheets
    By lexskoza in forum Excel General
    Replies: 6
    Last Post: 03-07-2017, 09:34 AM
  3. Applying Multiple Filter Criteria in one column of Excel
    By Philipsfn in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 07-14-2014, 05:29 PM
  4. Count records by applying filter to multiple columns
    By jituthejeet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-28-2014, 04:00 AM
  5. Applying Table Auto Filter to Multiple worksheets in a single Workbook
    By csivell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2012, 02:22 PM
  6. Applying Table Auto Filter to Multiple Worksheets in a Single Workbook and....
    By csivell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2012, 03:40 PM
  7. Applying a filter to multiple sheets
    By LemonTwist in forum Excel General
    Replies: 2
    Last Post: 07-15-2008, 04:49 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