PC Review


Reply
Thread Tools Rate Thread

Code that will rerun or refresh a pivot table (after new data ispasted into the original Pivot Table's Source Range)

 
 
Mike C
Guest
Posts: n/a
 
      13th Feb 2008
Hello,

I have created the following named range:

=OFFSET('FL1'!$A$12,0,0,COUNTA('FL1'!$A:$A),COUNTA('FL1'!$12:$12))

But I cannot figure out how to update a pivot table's results
automatically (after pasting a new set of data into the pivot table's
original source field.

In essence, I have a report that I need to pivot every morning
(sometimes 5-6 times per day). I am hoping to simply paste the new
data into the original tab where my prior day's report data existed,
and then click on a button that will update the pivot table results
for the new data.

Does anyone have a some code that would allow this?

I have not figured out how to do it........

THanks for any suggestions!
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      13th Feb 2008
This should handle all your needs:
Sub AllWorkbookPivots()
Dim pt As PivotTable
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws
End Sub

This, and other good things here:
http://www.ozgrid.com/VBA/pivot-table-refresh.htm


Regards,
Ryan--



--
RyGuy


"Mike C" wrote:

> Hello,
>
> I have created the following named range:
>
> =OFFSET('FL1'!$A$12,0,0,COUNTA('FL1'!$A:$A),COUNTA('FL1'!$12:$12))
>
> But I cannot figure out how to update a pivot table's results
> automatically (after pasting a new set of data into the pivot table's
> original source field.
>
> In essence, I have a report that I need to pivot every morning
> (sometimes 5-6 times per day). I am hoping to simply paste the new
> data into the original tab where my prior day's report data existed,
> and then click on a button that will update the pivot table results
> for the new data.
>
> Does anyone have a some code that would allow this?
>
> I have not figured out how to do it........
>
> THanks for any suggestions!
>

 
Reply With Quote
 
Roger Govier
Guest
Posts: n/a
 
      13th Feb 2008
Hi Mike

You could paste the following code onto the sheet containing the Pivot
Table.
As soon as you go to the PT after pasting your new data, the PT will refresh
as the sheet is activated.
You will need to change the name of the PT to match your own.
Right click on PT>Table Options>Name

Private Sub Worksheet_Activate()

ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh

End Sub


--
Regards
Roger Govier

"Mike C" <(E-Mail Removed)> wrote in message
news:67e4672d-4314-4cff-8755-(E-Mail Removed)...
> Hello,
>
> I have created the following named range:
>
> =OFFSET('FL1'!$A$12,0,0,COUNTA('FL1'!$A:$A),COUNTA('FL1'!$12:$12))
>
> But I cannot figure out how to update a pivot table's results
> automatically (after pasting a new set of data into the pivot table's
> original source field.
>
> In essence, I have a report that I need to pivot every morning
> (sometimes 5-6 times per day). I am hoping to simply paste the new
> data into the original tab where my prior day's report data existed,
> and then click on a button that will update the pivot table results
> for the new data.
>
> Does anyone have a some code that would allow this?
>
> I have not figured out how to do it........
>
> THanks for any suggestions!


 
Reply With Quote
 
Mike C
Guest
Posts: n/a
 
      15th Feb 2008
On Feb 13, 12:16*pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
wrote:
> This should handle all your needs:
> Sub AllWorkbookPivots()
> Dim pt As PivotTable
> Dim ws As Worksheet
> * * For Each ws In ActiveWorkbook.Worksheets
> * * * * For Each pt In ws.PivotTables
> * * * * * * * * * * pt.RefreshTable
> * * * * Next pt
> * * Next ws
> End Sub
>
> This, and other good things here:http://www.ozgrid.com/VBA/pivot-table-refresh.htm
>
> Regards,
> Ryan--
>
> --
> RyGuy
>
>
>
> "Mike C" wrote:
> > Hello,

>
> > I have created the following named range:

>
> > =OFFSET('FL1'!$A$12,0,0,COUNTA('FL1'!$A:$A),COUNTA('FL1'!$12:$12))

>
> > But I cannot figure out how to update a pivot table's results
> > automatically (after pasting a new set of data into the pivot table's
> > original source field.

>
> > In essence, I have a report that I need to pivot every morning
> > (sometimes 5-6 times per day). I am hoping to simply paste the new
> > data into the original tab where my prior day's report data existed,
> > and then click on a button that will update the pivot table results
> > for the new data.

>
> > Does anyone have a some code that would allow this?

>
> > I have not figured out how to do it........

>
> > THanks for any suggestions!- Hide quoted text -

>
> - Show quoted text -


....And you were right, the code you provided was just what I needed!
Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Used Range and Source data of a Pivot Table jh Microsoft Excel Programming 1 14th Mar 2010 09:19 PM
Auto Refresh Pivot Table after Source Data is Refreshed krysolov Microsoft Excel Programming 0 9th Feb 2010 09:53 PM
pivot table source data expand to new entries when refresh? DianneZ Microsoft Excel Misc 4 14th Oct 2008 03:58 PM
How to refresh a pivot table that uses changing source data Mike C Microsoft Excel Programming 1 13th Feb 2008 01:54 AM
Pivot tables, linking to a named range as a source to a pivot table Karen Microsoft Excel Misc 1 18th Oct 2003 01:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:20 AM.