Speeding Up Data Collection From Pivot Table

JonCrouch

New Member
Joined
Jul 1, 2008
Messages
4
have the following code which is supposed to list the items in a particularly Pivot Field from a Pivot Table in a different workbook. I have two questions; firstly is this code concise enough as it seems to take quite a long time for what it has to? Secondly, when I am running the code and I press escape it completes the macro in a very quick time and was wondering if I could code in a key press to simulate the escape key?
The code is
Code:
Sub Pivotfields()
With Workbooks("Pivot Data").Sheets("Pivot Tables").PivotTables("PivotTable15")
Sheet9.Range("A4").Select
    l = .PivotFields("Contract Number").PivotItems.Count
    k = 2
    Do
    ActiveCell.Value = .PivotFields("Contract Number").PivotItems(k).Name
    ActiveCell.Offset(1, 0).Activate
    k = k + 1
    Loop While k <> l
End With
End Sub
Edit : Forgot to mention that the PivotField list is only 200 items long and the code takes over a minute to complete and about 10 seconds when I press escape.
Any help would be much appreciated.
Regards,
Jonathan
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Could everything be recalculating? How about switching calculation mode to manual at the beginning of your code, and then resetting it as automatic afterwards? Look at Application.Calculation help.
 
Upvote 0
Perfect, thanks very much Glenn. Didn't know about the calculation trick, it has already been introduced to some of my other macros to great effect. Once again thanks.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top