+ Reply to Thread
Results 1 to 20 of 20

How do i change SourceData for all pivots in workbook while disconnect/connect slicers?

  1. #1
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Question How do i change SourceData for all pivots in workbook while disconnect/connect slicers?

    Been stuck on this for a while and cant figure it out. I've looked online on various sites and havent found anything close to what i need. Here is what i need to do...

    I have 6 Slicers in called "Quantrix" The slicers are called REG, DIRECTOR, AREA MANAGER, AOI, DMA, AG and CLOCK. I have 15 pivots (6 in Quantrix tab and 9 in a tab called "Pivots").

    I have vba code to update all pivot cache (showing 1 pivot update below) ...

    PHP Code: 
        Max Sheets("eLink_Raw").Cells(Rows.Count"A").End(xlUp).Row

        Sheets
    ("Quantrix").PivotTables("Quantrix 1").ChangePivotCache ActiveWorkbook_
          PivotCaches
    .Create(SourceType:=xlDatabaseSourceData:= _
          Sheets
    ("eLink_Raw").Range("A1:AW" Max).CurrentRegion _
          
    Version:=xlPivotTableVersion14
    Here is the code to disconnect SLICER, update source data for ALL pivots then reconnects slicer... This works great but its ONLY 1 SLICER

    PHP Code: 
     Dim vPivots As Variant
        Dim i 
    As Long

        Max 
    Sheets("eLink_Raw").Cells(Rows.Count"A").End(xlUp).Row

        With ActiveWorkbook
    .SlicerCaches("Slicer_REG").PivotTables
            
    If .Count 0 Then Exit Sub
            ReDim vPivots
    (1 To .Count)

            For 
    = .Count To 1 Step -1
                Set vPivots
    (i) = .Item(i)
                .
    RemovePivotTable (.Item(i))
            
    Next i

            
    For 1 To UBound(vPivots)
                If 
    1 Then
                    vPivots
    (1).ChangePivotCache _
                        ActiveWorkbook
    .PivotCaches.Create(SourceType:=xlDatabase_
                        SourceData
    :=Sheets("eLink_Raw").Range("A1:AW" Max).CurrentRegion)
                Else
                    
    vPivots(i).CacheIndex vPivots(1).CacheIndex
                End 
    If
                .
    AddPivotTable vPivots(i)
            
    Next i
        End With 
    How can i disconnects ALL Slicers, change source data for ALL Pivots then reconnect ALL slicers?

    I'm stuck. Any help will be greatly appreciated!

  2. #2
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    .......bump

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    This is not tested:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  4. #4
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Thanks for the reply Izandol!

    I did get a debug, "Application-defined or object-defined error", at the following code after it went through all the spreadsheets updating the pivot cache:
    PHP Code: 
              PT.CacheIndex lIndex 
    All Slicers disconnected beautifully

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    What is value of lIndex and PT.Cacheindex when the error occurs?

  6. #6
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    It doesnt say, where will i see that?

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    You may put cursor on the variables in break mode to see. Or you may try (again not tested because I am using tablet):
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Ok, it got past the previous part and now getting debug "run time error 424 object required' on last line of code here:

    PHP Code: 
       For Each vItem In vSlicers
          
    If oDic.Exists(vItemThen
             vPivots 
    Split(oDic(vItem), "|")
             
    With ActiveWorkbook.SlicerCaches("Slicer_" vItem).PivotTables
                
    For LBound(vPivotsTo UBound(vPivots)
                   .
    AddPivotTable vPivots(i
    vItem="REG" and vPivots(i)= "Quantrix 6"

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Oh I think this must be:
    Please Login or Register  to view this content.
    Change "sheet name" to match your sheet with slicers.

  10. #10
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Just ran it and it gave me a run time error on the same line, after it reconnects the slicers to the pivots in my "Quantrix" sheet it gives me a...

    Run-time error '1004'; Unable to get PivotTables property of the Worksheet class

    I changed it to "Pivots" which is where my other pivots are in and it kept running until it came time to do the next slicer. Had to change it to Quantrix then Pivots and so on.

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Ok we try again.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Question Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Stops here at the bottom of this code:

    PHP Code: 
        Dim PT                          As PivotTable
        Dim ptMain                      
    As PivotTable
        Dim ws                          
    As Worksheet
        Dim oDic                        
    As Object
        Dim sPivots                     
    As String
        Dim i                           
    As Long
        Dim lIndex                      
    As Long
        Dim Max                         
    As Long
        Dim vPivots
        Dim vSlicers
        Dim vItem

       vSlicers 
    = Array("REG""DIRECTOR""AREA_MANAGER""AOI""DMA""AG""CLOCK")
       
    Set oDic CreateObject("Scripting.Dictionary")

       
    Max Sheets("eLink_Raw").Cells(Rows.Count"A").End(xlUp).Row
       
    For Each vItem In vSlicers
          With ActiveWorkbook
    .SlicerCaches("Slicer_" vItem).PivotTables
             
    If .Count 0 Then

                
    For = .Count To 1 Step -1
                   sPivots 
    sPivots "|" & .Item(i).Name
                   
    .RemovePivotTable .Item(i
    .Item(i)= "Fut Week 2"
    (1)= 15

    I really appreciate all your help thus far!

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    What is the error? I do not understand this because this line has worked before - do you test with the original file?

  14. #14
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    I have created test file and this script is working with it:
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    11-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Izandol,
    Tried it with a clean, archived workbook and it worked beautifully. You are genius!!!!

    Thank you, thank you, thank you!

  16. #16
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    You are welcome. Was interesting new thing to learn.

  17. #17
    Registered User
    Join Date
    05-11-2016
    Location
    OTA
    MS-Off Ver
    2010
    Posts
    10

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    I'm a noob but trying to learn...

    I don't really know how this one is working... what should I replace in this piece of code (beside the name of the spreadsheet with all my slicers)?

    thank you a lot

  18. #18
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Vincent welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  19. #19
    Registered User
    Join Date
    07-04-2016
    Location
    ABC
    MS-Off Ver
    2013
    Posts
    1

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    Intresting, i am dealing with multiple slicers(more than 60) and do not have control over names...how can i make code dynamic for slicers that can disconnect, update and reconnect.

  20. #20
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: How do i change SourceData for all pivots in workbook while disconnect/connect slicers

    lavansayshi welcome to the forum

    Perhaps you missed my post 18?
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

+ 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. Replies: 0
    Last Post: 10-18-2013, 11:35 AM
  2. Connect/disconnect separate data points in line chart?
    By goldfrapp01 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-02-2013, 07:21 AM
  3. Shared Workbook - how to disconnect the pop-up...
    By bondcrash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2006, 10:20 AM
  4. create custom menu with addin connect/disconnect
    By dayanand108 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-10-2005, 09:05 AM
  5. How to use ADO to change Pivottable sourcedata query
    By Chace in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-17-2005, 02:06 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