+ Reply to Thread
Results 1 to 2 of 2

Button to change pivot table sources

  1. #1
    Registered User
    Join Date
    10-31-2013
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Button to change pivot table sources

    Hi there,

    I've got a very basic understanding of VBA.

    My goal is to create a button that will do the following:

    Prompt a pop-up to for data source for all pivot tables in the file. (Source is usually external file sitting on NAS)

    If opted 'cancel' than do nothing if new source selected refresh all pivot tables as well.

    All pivots share the same cache. So is the only single slicer linked to all pivot tables and as I understand needs to be disconnected and then reconnected.

    I tried to replicate other posts but to no avail. Definitely know that I'm missing the slicer connecting and disconnecting parts.

    Many thanks in advanced.

    Option Explicit


    Private Sub Data Source_Click()

    Sub ChangeSourceData()

    Dim Wks As Worksheet
    Dim PT As PivotTable
    Dim UserRange As Range
    Dim SourceData As String
    Dim CacheIndex As Long
    Dim Cnt As Long

    On Error Resume Next
    Set UserRange = Application.InputBox( _
    Prompt:="Select the range for the source data.", _
    Title:="Select a range", _
    Type:=8)
    On Error GoTo 0

    If UserRange Is Nothing Then Exit Sub

    SourceData = Application.ConvertFormula(UserRange.Address(, , , True), xlA1, xlR1C1)

    Cnt = 0
    For Each Wks In ActiveWorkbook.Worksheets
    For Each PT In Wks.PivotTables
    Cnt = Cnt + 1
    If Cnt = 1 Then
    PT.ChangePivotCache ThisWorkbook.PivotCaches.Create(xlDatabase, SourceData)
    CacheIndex = PT.CacheIndex
    Else
    PT.CacheIndex = CacheIndex
    End If
    Next PT
    Next Wks

    End Sub

  2. #2
    Registered User
    Join Date
    10-31-2013
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Button to change pivot table sources

    Bump. Bump. Bump.


+ 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. Pivot table with two data sources
    By Jonathan9 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-08-2014, 03:10 AM
  2. Replies: 0
    Last Post: 08-09-2013, 12:32 PM
  3. Pivot Table Multiple Sources
    By billykiller05 in forum Excel General
    Replies: 1
    Last Post: 12-04-2008, 04:29 AM
  4. Pivot table - multiple sources
    By BC... in forum Excel General
    Replies: 3
    Last Post: 05-11-2006, 08:02 PM
  5. [SOLVED] Pivot table, two data sources.
    By Erasmus Bowen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2005, 01:05 PM
  6. Multiple MS Access table sources for pivot table
    By fbj in forum Excel General
    Replies: 5
    Last Post: 08-15-2005, 11:05 AM

Tags for this Thread

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