View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default Sort Pivot Table by Gran total automaticaly

If you can do it manually, just turn on the macro recorder before running
through the steps. When you are done with the sort, turn off the macro
recorder and view the code by hitting Alt+F11 on your keyboard.
Also, compare your recorder code to this code:
Sheets("Sheet1").Select
Range("A1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
Sheets("Sheet1").Range("A1").CurrentRegion).Create PivotTable _
TableDestination:=Sheets("Sheet2").Range("A3"),
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10

Pay attention to this part:
Sheets("Sheet1").Range("A1").CurrentRegion).

You will need to replace your recorded code with that snippet of code
(change the sheet name so it matches yours). That will give you a dynamic
range; you always capture all the data for your Pivot Table. Otherwise, you
will have a fixed (or absolute range) and if you have more data than what is
in the recorded macro, you will miss what is at the bottom; quite simply your
Pivot Table will display incorrect results.

Give it a go and let me know how it works out for you!!

HTH,
Ryan---



--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Alberto Ast" wrote:

How do I sort my pivot table by the grand total...? I can do it manualy but
if I change the criteria I loose the sorting and have to select all the data
and manually sort it again.