• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Dashboard loads Data

ianb

Member
Hi,


I need to upload my Access data into my dashboard.

Also I need to have a program running once the data is loaded.


This is in one of the sheets


Option Explicit

Private Sub Worksheet_PivotTableUpdate(ByVal target As PivotTable)

SyncPivotFields2 target

End Sub


This is the module that will sync my pivot tables.


My Dashboard hangs and then errors. I need to uplaod the data first before this runs.


How is this possiable to do ?


Thanks.
 
How Can I make all the VBA program wait until the data has uploaded.


I have multi pivot table connections therefore I have to wait approx 2 minutes for all the data to upload before it attempts to run a vba program.


One of the programs starts when it is uploading causing an error, crash or locking on the worksheets / file. .xlsm


Thanks.
 
Hi Ian ,


This is probably not relevant to your question , but have you gone through this ?


http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/A_3172-How-to-Automatically-Update-Your-PivotTables-and-PivotCharts.html


Narayan
 
Hi Nara,


I think the program you have directed me to may be the solution.


Initially it could work. Also If I am doing a full update another program would just do the refresh.all hence I can switch off all automatic updates. How does that sound.


The question would now be can I incorporate the pivot update program and the active sheet together. The active sheet to work only once and then the pivot update program to work each time a pivot table is change.


Would it be best this way listed below. Is it this simple ? or do you havea better idea ?


Option Explicit


Private Sub Workbook_SheetActivate(ByVal Sh As Object)


Dim PC As PivotCache

For Each PC In Me.PivotCaches

PC.Refresh

Next


End Sub


Private Sub Worksheet_PivotTableUpdate(ByVal target As PivotTable)

SyncPivotFields2 target

End Sub
 
The only other idea is just do active sheet refresh once per load of the spreadsheet !!

Is this possiable (do once only ?)


Many thanks. I have more ideas hopefully leading to a solution.
 
OR.... final idea.


It upalods all the data (reading data)


Then when I click on a tab it loads the


Can I have when sheet is active worksheet pivot table update only as the pivot tables have already been refreshed.


How can this program list below work ? third line starting worksheet would need editing.

Any Ideas ? I think this would be the solution.....


Option Explicit

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

Worksheet_PivotTableUpdate(ByVal target As PivotTable)

SyncPivotFields2 target

End Sub
 
Hi Ian ,


I am not sure I get your exact processes :


1. There is an Upload process , which transfers data from Access to Excel


2. There is a process which syncs all your pivot tables ; is this the same as refreshes all your pivot tables ?


3. There is a process which refreshes all your pivot tables


Is this correct ? Is the order correct ?


The Worksheet_PivotTableUpdate Event procedure is triggered when a PivotTable report is updated on a worksheet ; is this by process 2 or process 3 above ? It is not necessary to call it from within any other procedure , since it is an event procedure , and is automatically triggered by the pivot table being updated.


Narayan
 
1. Excel Dashboard loads and automatically refreshes the pivot tables (all pivot tables set to refresh when opening.


2. I have a program that sync soem of the pivot tables .e.g if 1,4,6 pivot tables are changed with the date or the person then the others changes. I can send you the full program.


I am finding that when Option one is running then option two run when it is still doing the refresh. option 2 starts and option 1 does not get completed.


This is option 2 found on 5 of the 13 sheets as they contain multi pivot tables that are synced together :


Option Explicit

Private Sub Worksheet_PivotTableUpdate(ByVal target As PivotTable)

SyncPivotFields2 target

End Sub


I think the best question would be how can I refresh all my pivot tables on loading the dashboard whith out starting this program listed above for syncing my pivot tables together until I click on a pivot tables and change the date ?


I can list the full program in a demo spreasheet if required as it is an amazing program I found and adapted if required.


many thanks. Ian.
 
Hi, Here is the full program that conficts with the loading of the data into the dashboard pivot tables.


I need to update/ refresh all before this program becomes active.


Option Explicit


Sub SyncPivotFields(target)

'downloaded from www.contextures.com

'revised code by Jeff Weir, August 2012


' Date Ini Modification

' 20/09/12 JSW Added ability to exclude PivotFields, and

' also extended code to sync slave RowFields


'specify any PivotFields that you DON'T want to check

'in section marked with '#######


'specify any WorkSheets that you DON'T want to check

'in section marked with '*******


'specify any PivotTables that you DON'T want to change (but that are in WorkSheets that you DO want to check)

'in section marked with '=======


Dim TimeTaken As Date


TimeTaken = Now()


Dim pf_Master As PivotField

Dim pt_Master As PivotTable

Dim pi_Master As PivotItem

Dim bPageField As Boolean

Dim bFiltered As Boolean

Dim bUseDictionary As Boolean

Dim bMI As Boolean

Dim bFoundAll As Boolean

Dim dicPivotItems As Object '(We are using late binding. 'If we were using early binding we would have used this: Dim dicPI_MasterItems As Scripting.Dictionary

Dim wks As Worksheet

Dim pt_slave As PivotTable

Dim pf_Slave As PivotField

Dim pi_Slave As PivotItem

Dim varMasterItems As Variant

Dim lngFound As Long

Dim lngVisibleItem As Long

Dim lngVisibleItems As Long


Application.EnableEvents = False

Application.ScreenUpdating = False


Set pt_Master = target


On Error GoTo errhandler


'Cycle through all pagefields in the master pivot table

'

For Each pf_Master In pt_Master.VisibleFields

If pf_Master.Orientation = xlPageField Then

Select Case pf_Master.Name

'########################################################################################

'Here's where we list any PivotFields in the master pivot that we want to ignore

' You simply list the pivotfield name in quotes, with the word Case in front.

' e.g. Case "SomePivotfieldWeDontWantToChange"


' For instance, for this particular example, if we had a field called "ExampleField"

' then we could have the code skip it by adding this:


' Case "Resolved Date"

' Case "Item"


'do nothing


' The 'do nothing comment is completely optional and in fact does nothing other than

' make it clear to anyone reading the code that the macro does not proces this field


'########################################################################################


Case Else

bFiltered = Not pf_Master.AllItemsVisible

bMI = pf_Master.EnableMultiplePageItems

If bMI Then 'there's possibly more than one visible field, so we need to find out which ones

If bFiltered Then 'if NO fields are filtered, then no need to find out which ones. But otherwise we do.

ReDim varMasterItems(0) 'Reset the array

lngVisibleItems = 0 'reset the counter

For Each pi_Master In pf_Master.PivotItems

If pi_Master.Visible Then 'add any visible pivotitems to our master list

ReDim Preserve varMasterItems(lngVisibleItems)

varMasterItems(lngVisibleItems) = pi_Master.Name

lngVisibleItems = lngVisibleItems + 1

If Not bMI Then Exit For 'there is only one item, and we just found it. So we can continue to next part of routine

End If 'If pi_Master.Visible Then

Next pi_Master

End If 'If bFiltered Then

Else

ReDim varMasterItems(0) 'Reset the array

varMasterItems(0) = pf_Master.CurrentPage.Name

lngVisibleItems = 1

End If 'If bMI Then

For Each wks In ThisWorkbook.Worksheets


Select Case wks.Name

'**********************************************************************************************************

'Here's where we list any WORKSHEETS that we DO NOT want to check

' You simply list the worksheet name in quotes, with the word Case in front.

' e.g. Case "Some Unimportant Sheet"


Case "Dashboard (Detailed)"

Case "Dashboard (Group)"

Case "PSO Arrival Table"

Case "PSO Passed Table"


' You can add an optional 'do nothing comment on the following line if you like.

' This makes it clear to anyone reading the code that the macro does not proces this sheet


'***********************************************************************************************************


Case Else

For Each pt_slave In wks.PivotTables

Select Case wks.Name & "_" & pt_slave.Name

Case ActiveSheet.Name & "_" & pt_Master.Name

'do nothing: This is the master pivot that we just changed.


'===============================================================================================================

'Here's where we list any PIVOTTABLES that we DO NOT want to check.


' You simply list the worksheet name then an underscore, then the pivottable name, all in quotes, with the word Case in front.

' e.g. for a PivotTable called "Do not show" in a worksheet called "My Pivots" you would do this (WITHOUT the apostrophe in front):

' Case "My Pivots_Do not show"


'Case "Dashboard (Open Daily)"


Case "Dashboard (Open Multi)_PivotTable5"

Case "Dashboard (Open Multi)_PivotTable6"


'Case "Dashboard (Overview)"

'Case "Dashboard (Detailed)"


Case "Dashboard (Individual)_PivotTable1"

Case "Dashboard (Individual)_PivotTable2"

' You can add an optional 'do nothing comment on the following line if you like.

' This makes it clear to anyone reading the code that the macro does not proces this PivotTable

'do nothing

'===================================================================================================================


Case Else

pt_slave.ManualUpdate = True

For Each pf_Slave In pt_slave.VisibleFields

bPageField = False

If pf_Slave.Orientation = xlPageField Then bPageField = True

If pf_Slave.Name = pf_Master.Name Then

pf_Slave.ClearAllFilters

If Not bFiltered Then

' Nothing in pf_Master is filtered.

' Neither is anything in pf_Slave, because we've just cleared filters above.

' So if the slave field is a page field, then just

' change the .EnableMultiplePageItems checkbox to match the Master

If pf_Slave.Orientation = xlPageField Then pf_Slave.EnableMultiplePageItems = bMI

Else:


Select Case bMI

Case False

' "Enable Multiple Items" setting is set to False.

' So pf_Master has either ONE item selected, or All items selected.

' Which is great, because IF pf_Slave is ALSO a page field, we can

' set it to the same setting with just 2 lines of code

If pf_Slave.Orientation = xlPageField Then

pf_Slave.EnableMultiplePageItems = False

pf_Slave.CurrentPage = pf_Master.CurrentPage.Value

Else:

' Damn, pf_Slave is NOT a pagefield, so we can't set it to the same settings.

bUseDictionary = True


End If ' If pf_Slave.Orientation = xlPageField Then

Case True ' More than one (but less than all) items are selected, so we'll have to use the Dictionary

bUseDictionary = True

End Select ' Select Case bMI

If bUseDictionary = True Then

' Either pf_Master has multiple items,

' OR pf_Slave is a rowfield. So we have to change filter via below approach

If pf_Slave.Orientation = xlPageField Then pf_Slave.EnableMultiplePageItems = True

' Dump the contents of our master list into a dictionary

' Note that you CAN'T do this by going Set Dictionary1 = Dictionary2,

' because any changes you make in one would be reflected in the other.

Set dicPivotItems = Nothing

Set dicPivotItems = CreateObject("Scripting.Dictionary")

For lngVisibleItem = 0 To UBound(varMasterItems)

dicPivotItems.Add varMasterItems(lngVisibleItem), varMasterItems(lngVisibleItem)

Next lngVisibleItem

' Dump ALL PIs of matching PFs from slave PT to that dictionary.

' If there is a match, VBA will throw an error and we will know to NOT hide that item.

' IF there is no match (and no error), we SHOULD hide that item

On Error Resume Next

lngFound = 0

For Each pi_Slave In pf_Slave.PivotItems

If lngFound = lngVisibleItems Then

' We've found all the visible items, so just hide the remainder without checking

pi_Slave.Visible = False

Else:

' We haven't yet found all the visible items, so keep checking.

dicPivotItems.Add pi_Slave.Name, pi_Slave.Name

If Err.Number = 0 Then

' It's not one of the master visible items, so hide it

pi_Slave.Visible = False


Else:

Err.Clear

lngFound = lngFound + 1

End If ' If Err.Number = 0

End If ' If lngFound = lngVisibleItems

Next pi_Slave

On Error GoTo 0

End If ' If bUseDictionary = True Then

bUseDictionary = False

End If ' If Not bFiltered Then

End If ' If pf_Slave.Name = pf_Master.Name

Next pf_Slave

End Select ' Select Case wks.Name

pt_slave.ManualUpdate = False

Next pt_slave

End Select

Next wks

End Select ' Select Case pf_Master.Name

End If ' If pf_Master.Orientation = xlPageField Then

Next pf_Master

errhandler:

If Err.Number <> 0 Then

MsgBox Err.Description, vbCritical, "Whoops, something went wrong..."

Else

TimeTaken = Now() - TimeTaken

Debug.Print Now() & " SyncPivotFields took " & Format(TimeTaken, "HH:MM:SS") & " seconds."

End If

Application.EnableEvents = True

Application.ScreenUpdating = True


End Sub


'Private Sub Worksheet_PivotTableUpdate(ByVal target As PivotTable)

'SyncPivotFields target

'End Sub
 
Hi Ian ,


So the point is that the pivot tables are all refreshed when your workbook opens ; they are refreshed in some arbitrary sequence , which does not reflect the order of dependencies.


So if pivots 1 , 4 and 6 are to be synced together , then the Worksheet_PivotTableUpdate event procedure is getting triggered when pivot 1 gets updated , and when 4 and 6 have not yet been updated ; is this correct ?


If so , then the best way to take care of this is to set up global counters for each set of pivot tables ; suppose pivot tables 1 , 4 and 6 are to be synced together , then set up a counter which is incremented by the master procedure , each time one of these pivot tables ( 1 , 4 , 6 ) is refreshed ; the Worksheet_PivotTableUpdate event procedure should have a preliminary section where for each set of pivot tables , the corresponding counter will be checked ; thus if the Worksheet_PivotTableUpdate event procedure is called with the target as pivot table 1 , then the check will be to see if the corresponding global counter has reached a value of 3 ; only if it has then the sync procedure is executed , otherwise the procedure just exits doing nothing.


Narayan
 
Hi,


Thanks for the answer. I understand what you are saying.


I just need to find the solution.


If Worksheet_PivotTableUpdate is called >1 then execute else exit.


I will look into this further. Thanks for the advise and guidance.
 
Back
Top