+ Reply to Thread
Results 1 to 2 of 2

Filter Macro

  1. #1
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    Filter Macro

    Hi,

    If column "A" has several different type of class IDs and my macro filtered by one class ID and column "B" is left with 4 different departments after the filtered. How do I write a macro to select 3 departments out of the 4 departments in column "B"? I want a macro to be dynamic, so that when a new department is added it will filter 4 departments, and leave just one department. It will always uncheck department 4. Make senses?

    My current code is as follow (this code works, but when a new department added, it will not capture the new department):

    Please Login or Register  to view this content.
    Thank you for your help

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Filter Macro

    First of all it looks like you might be missing a closing parenthesis.

    Here's how I would do it. Make a pivot table on your data with totals. The only thing in this pivot table should be the department name in the row area. This gives you a unique list of departments. I did this on a tab called pivots. I took the results and made a named dynamic range out of them called Departments. =OFFSET(Pivot!$A$2,0,0,COUNTA(Pivot!$A:$A)-1,1).

    Then I used the following VB code to generate a list of departments other than department 4.
    Please Login or Register  to view this content.
    You should be able to plug this function into your code.

    Please Login or Register  to view this content.

+ 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. Macro to filter a pivot whilst looping through filter criteria in a variable list.
    By Alistairm88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2015, 04:25 AM
  2. [SOLVED] I need formula or macro to filter a number of items from different tables at single filter
    By Karthikeyannb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2014, 11:04 AM
  3. Need to filter a report filter based on the previous filter
    By elliotencore in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-28-2014, 07:44 AM
  4. Replies: 5
    Last Post: 12-19-2013, 06:58 AM
  5. Filter Macro (range contained in filter value)
    By antman10 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-28-2010, 11:09 PM
  6. Advanced Filter Macro - Won't run the filter
    By dsil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-18-2008, 11:59 AM
  7. [SOLVED] Need macro to filter, create tab on filter and copy/paste
    By Jen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2006, 11:50 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