+ Reply to Thread
Results 1 to 2 of 2

need help with pivotitem loop. not working

Hybrid View

  1. #1
    Registered User
    Join Date
    05-04-2015
    Location
    Irvine, CA
    MS-Off Ver
    2010
    Posts
    37

    need help with pivotitem loop. not working

    I am trying to filter out everything with VBA and select only those items that I need. I had found something similar to the code previously on the internet. However, it doesn't seem to work

    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Make Buy")
        For i = 1 To .PivotItems.Count
            .PivotItems(i).Visible = False
    Next i
    On Error Resume Next
            .PivotItems("MAKE").Visible = True
    End With
    I want to deselect everything. and then select only MAKE. if there are situations where there are NEW items added, it should be able to catch those as well.

  2. #2
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: need help with pivotitem loop. not working

    It doesn't like you deleting all of the items before you add back in the one you want.
    something like the below (if "make" definitely exists, otherwise you can catch your errors).

    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Make Buy")
        For i = 1 To .PivotItems.Count
          .PivotItems("MAKE").Visible = True
           If .PivotItems(i).Name = "MAKE" Then
            Else
           .PivotItems(i).Visible = False
           End If
    Next i
    End With

+ 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. For loop within loop not working correctly
    By HalPlz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-25-2015, 12:06 AM
  2. [SOLVED] Pivottable - cycle through each PivotItem
    By rasonline in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2014, 05:22 AM
  3. Replies: 0
    Last Post: 06-14-2013, 12:33 PM
  4. PivotItem update error
    By wjones in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2010, 04:25 PM
  5. Set PivotItem using counter
    By CinqueTerra in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-02-2005, 01:40 PM
  6. PivotItem.Visible
    By Excelgeek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2005, 07:05 PM
  7. [SOLVED] PivotItem positioning...
    By Jesterhoz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2005, 10:05 PM

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