Consulting

Results 1 to 2 of 2

Thread: Loop through array of buttons on a Pivot table

  1. #1
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location

    Question Loop through array of buttons on a Pivot table

    Hello.

    Please could someone help.

    I have this code that selects each item/button on the pivot table - but the code I not efficient as i would like it loop to a hundred.

    Sub Macro13()
    
    
        ActiveWorkbook.Slicer("SlBook").ItemsList = _
            Array( _
            "[100].[DayNo].&[1]")
        
        ActiveWorkbook.Slicer("SlBook").ItemsList = _
            Array( _
            "[100].[DayNo].&[1]", "[100].[DayNo].&[2]")
        
        ActiveWorkbook.Slicer("SlBook").ItemsList = _
            Array( _
            "[100].[DayNo].&[1]", "[100].[DayNo].&[2]", _
            "[100].[DayNo].&[3]")
        
        ActiveWorkbook.Slicer("SlBook").ItemsList = _
            Array( _
            "[100].[DayNo].&[1]", "[100].[DayNo].&[2]", _
            "[100].[DayNo].&[3]", "[100].[DayNo].&[4]")
    
    End Sub

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Perhaps:
    [vba]Sub Macro13()
    Dim aItems(99)
    Dim n As Long
    For n = 0 To 99
    aItems(n) = "[100].[DayNo].&[" & n + 1 & "]"
    Next n
    ActiveWorkbook.Slicer("SlBook").ItemsList = aItems

    End Sub
    [/vba]
    Be as you wish to seem

Posting Permissions

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