View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alberto Ast[_2_] Alberto Ast[_2_] is offline
external usenet poster
 
Posts: 181
Default pivot table variable range within a macro

Still can not mate it to work.. I have the data in Sheet1 already used to
create the table... simple data table... then on Sheet2 I have the PT... I
have typed your macro and then execute it from Sheet2, I select the range on
Sheet1 and put the cursor inside the PT and then execute the macro but it
does not work.

Any thoughts?

"smartin" wrote:

It works in the somewhat limited case where the cursor is in the pivot
table to refresh, Sheet1 contains its data source, and Sheet1 is nicely
structured such that UsedRange supplies a range a pivot table can work
with.

In the code you will need to modify "Sheet1" with an appropriate
reference to your source data sheet.

However, if the source data sheet has multiple areas for various pivot
tables, or is not nicely structured, we will need to add code.

Alberto Ast wrote:
I could not make it to work... have a couple of questions...

My souce data sheet is different than my PT sheet... will this work with
your macro?
If I have several PT in same page how does the macro knows which table to
update...? I did not see a reference to a specific table.


"smartin" wrote:

Alberto Ast wrote:
Can I modify the pivot table range within a macro so once I update the table
it will pick up all the way to end of data?

What I do is to consider the table up to 10,000 rows but still I am limiting
to what ever I put in such number.
Try this with the PT worksheet selected. Assumes source data on Sheet1.

Sub UpdatePT
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
Sheets("Sheet1").UsedRange
'or, if you are like me, specify the entire column and never worry
'about it again
' ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
Sheets("Sheet1").UsedRange.EntireColumn
End Sub