LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default Can I Sort (A-Z or Z-A) Pivot Table Data or Fields using VBA?

Hi,
I have some VBA that makes changes to multiple Pivot fields at once to show
various data in a Pivot Chart.

Is there a clean way to have VBA sort the Pivot by say the Grand Total
Column (either reverse or ascending) so that the pivot bar chart looks like a
pareto.... tallest bars at the left of the stacked bar chart?

As an example of a simple single column ("Customer") & row ("Group") field,
I want to sort the data so that the customer with highest sales is at the
top of the list.

Here's a recording of a macro but it just seems to reference cells in the
worksheet. The problem is that if I change the colum/row fields, the
cell/column/row of the total will also change.

Range("I7").Select
Selection.Sort Key1:="R7C9", Order1:=xlAscending, Type:=xlSortValues, _
OrderCustom:=1, Orientation:=xlTopToBottom
Selection.Sort Key1:="R7C9", Order1:=xlDescending, Type:=xlSortValues, _
OrderCustom:=1, Orientation:=xlTopToBottom
Range("A7").Select
Selection.Sort Order1:=xlAscending, Type:=xlSortLabels, OrderCustom:=1, _
Orientation:=xlTopToBottom
Range("B6").Select
Selection.Sort Order1:=xlAscending, Type:=xlSortLabels, OrderCustom:=1, _
Orientation:=xlLeftToRight
Selection.Sort Order1:=xlDescending, Type:=xlSortLabels, OrderCustom:=1, _
Orientation:=xlLeftToRight

 
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
VBA Pivot Table help with data fields James Excel Discussion (Misc queries) 3 August 13th 09 05:15 PM
Issue with Multiple sort fields in pivot table Mark b. Excel Programming 0 February 11th 09 04:28 PM
Data Fields in Pivot Table MichaelR Excel Programming 1 July 24th 08 07:07 PM
Data Fields in Pivot Table MichaelR Excel Discussion (Misc queries) 0 July 22nd 08 06:36 PM
changing sort for pivot table fields Stan R Excel Programming 1 August 16th 03 12:32 PM


All times are GMT +1. The time now is 04:03 PM.

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

About Us

"It's about Microsoft Excel"