+ Reply to Thread
Results 1 to 4 of 4

Macro that would filter pivot table top 10 items

  1. #1
    Registered User
    Join Date
    05-29-2013
    Location
    massachusetts, usa
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro that would filter pivot table top 10 items

    Hi, I am running into the "Run time error '1004': Autofilter method of Range Class failed" when i tried to run the macro for the auto filter that i recorded . It is a relatively simple macro, not sure why it isnt working...

    Code:

    Sub TopCus()
    '
    ' TopCus Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+T
    '

    ActiveSheet.Range("$A$4:$K$1112").AutoFilter Field:=11, Criteria1:="10", _
    Operator:=xlTop10Items


    End Sub

    Please help!!! Thanks!!
    W

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Macro that would filter pivot table top 10 items

    well, are you using the same exact range for the data? Do you need to alter $A$4:$K$1112 ?

    --

    In general, you would be wise to create a named range or table object for the table you want to filter in this way. you can then include the range in the macro by name (which is good for future runs when the row count is different). Example below:

    ActiveSheet.ListObjects("TABLE_NAME").Range.AutoFilter Field:=1, Criteria1:= _
    "10", Operator:=xlTop10Items
    Last edited by GeneralDisarray; 05-29-2013 at 01:25 PM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    05-29-2013
    Location
    massachusetts, usa
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro that would filter pivot table top 10 items

    Hi, sorry i am very new in this. Did you mean defining the pivot table in the worksheet?

    And yes, the range is the same..

    Thanks,
    W

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Macro that would filter pivot table top 10 items

    can you upload an example? pretty sure i can help you out

    --

    yes, you can access a pivot table by name also. Here's an example i just recorded from a pivot table of my own. You can edit this to reflect your information

    ActiveSheet.PivotTables("PivotTable1").PivotFields("Row_label_name").PivotFilters. _
    Add Type:=xlTopCount, DataField:=ActiveSheet.PivotTables("PivotTable1"). _
    PivotFields("CustomerFieldName"), Value1:=10
    Last edited by GeneralDisarray; 05-29-2013 at 01:32 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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