Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to update pivot table data range

Hi all,
I am trying to create Macro in excel 2010 which will change the data range for a pivot table if have added extra datainto the source data worksheet. This is the macro belowbut it returns a runtime error 5 "Invalid procedure Call) error:

Sub ChangePivotTableDataRange()

ActiveSheet.PivotTables("PivotTable1").ChangePivot Cache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Worksheets("Sales").Range("A5").Curren tRegion.Address _
, Version:=xlPivotTableVersion14)

End Sub

Any help on this would be greatly appreciated.

Taffy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Macro to update pivot table data range

Taffy,

I think the issue is in the "SourceData" argument. If you change it to:

SourceData:="Sales!" & Worksheets("Sales").Range("A5").CurrentRegion.Addr ess

it should work.

Hope this helps,
Ben
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to update pivot table data range

On Sunday, 9 September 2012 19:53:38 UTC+1, (unknown) wrote:
Taffy,



I think the issue is in the "SourceData" argument. If you change it to:



SourceData:="Sales!" & Worksheets("Sales").Range("A5").CurrentRegion.Addr ess



it should work.



Hope this helps,

Ben


Hi Ben,
Thanks for your help - it worked a treat! I'm always amazed at how quick you guys post your responese.

Thanks again,

Taffy
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Macro to update pivot table data range

Glad it worked, and happy to help.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
update pivot table data range JN[_2_] Charts and Charting in Excel 2 September 29th 08 08:40 PM
Auto Update Range of a Pivot Table TJDeborah[_2_] Excel Programming 1 April 19th 06 01:31 PM
How do I set the pivot table to auto-update the data range? Toni @ Fidelity Excel Discussion (Misc queries) 3 March 17th 06 09:45 PM
Macro to update pivot table data range Mike_M Excel Programming 2 May 25th 05 04:02 PM
Update Data Field in Pivot Table with Dynamic Excel Range ExcelMonkey[_97_] Excel Programming 1 March 3rd 04 08:16 PM


All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"