hi, below you can find the vba that i wrote (with some help from the internet).
Basically, i loop through slicer values (about 3 000 items) and copy / paste a range of calculated values to a worksheet.
The problem is though, the values from the pivot table and thus the slicer come from a SQL server (datawarehouse), and that i have to make sure that all the SQL queries are updated before copying the values to the worksheet.
The cells i now get copy/paste only contains "#GETTING_DATA...

How can i force the vba macro to wait untill all the formules and all the queries are updated before continuing the routine?
Since my workbook connects to an SQL server, i cannot upload my worksheet.

thanks in advance, steven.




Sub LoopSlicerRelatienummer()

Dim sC As SlicerCache
Dim SL As SlicerCacheLevel
Dim sI As SlicerItem
Set sC = ActiveWorkbook.SlicerCaches("Slicer_Relatienummer")
Set SL = sC.SlicerCacheLevels(1)

Sheets("_DataCustomer").Select
Rows("3:3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

For Each sI In SL.SlicerItems
sC.VisibleSlicerItemsList = Array(sI.Name)
'MAKE SURE ALL BACKGROUND QEURIES ARE FINISHED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Range("F1:AO1").Select
Selection.Copy
Sheets("_DataCustomer").Activate
lastrow = Range("A65536").End(xlUp).Row
Cells(lastrow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets("Klantfiche").Activate

Next

End Sub