pivot tables orientation
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Pivot Tables - Orientation issues?

Pivot Tables - Orientation issues?

resolvedResolved · Medium Priority · Version 2003

replyReply Mon 6 Oct 2008, 19:11Delegate Richard said...

Richard has attended:
Excel VBA Intro Intermediate course

Pivot Tables - Orientation issues?

Hi there,

I am trying to write the correct procudure to create a pivot table. I have recorded a macro which does the job, as below;

Recorded Procedure:

Sub CreatePivotTable()

Sheets("AR134_VBA_Template").Select
Range("A8").Select
Selection.CurrentRegion.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"AR134_VBA_Template!R1C1:R897C4").CreatePivotTable TableDestination:="", _
TableName:="PivotTable2"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable2").SmallGrid = False
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array( _
"Customer Name", "Data")
With ActiveSheet.PivotTables("PivotTable2").PivotFields("91-180 Days Past Due")
.Orientation = xlDataField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("180+ Days Past Due")
.Orientation = xlDataField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable2").PivotFields("91 Days+").Orientation = _
xlDataField


Range("B3").Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Data")
.Orientation = xlColumnField
.Position = 1
End With
Application.CommandBars("PivotTable").Visible = False


End Sub

*Please notice the last part:

Range("B3").Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Data")
.Orientation = xlColumnField
.Position = 1
End With

I have then tried to write this 'macro' into a procedure and tried to change the PivotFields, e.g.("91 Days+") orientation from xlDataField to xlColumnField, as below;

Altered Procedure:

Sub CreatePivotTable()

Sheets("AR134_VBA_Template").Select
Range("A8").Select
Selection.CurrentRegion.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"AR134_VBA_Template!R1C1:R897C4").CreatePivotTable TableDestination:="", _
TableName:="PivotTable2"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable2").SmallGrid = False
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array( _
"Customer Name", "Data")
With ActiveSheet.PivotTables("PivotTable2").PivotFields("91-180 Days Past Due")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields("180+ Days Past Due")
.Orientation = xlColumnField
.Position = 1
End With

With ActiveSheet.PivotTables("PivotTable2").PivotFields("91 Days+")

.Orientation = xlColumnField
.Position = 1
End With

Application.CommandBars("PivotTable").Visible = False

End Sub


The Recorded Procedure works just fine, but the Altered Procedure does not, it comes out as a blank pivot table, please could someone explain to me what im doing wrong and why? + I've also tried changing the 'Positions' of the column fields to 1, 2 & 3 respectively, but that doesnt work either. If you could let me know what the last bit of the recorded macro is doing, the

Range("B3").Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Data")
.Orientation = xlColumnField
.Position = 1
End With

bit.

I hope the above is possible to understand, I do appreciate this may be difficult without seeing the actual data being used.

Thanks for your time.

For upcoming training course dates see: Pricing & availability

replyReply Tue 14 Oct 2008, 10:19Trainer Stephen said...

RE: Pivot Tables - Orientation issues?

Hi Richard

Thank you for your qustion.

It is very hard to understand your problem without seeing the workbook and how the code runs. Could you email me a copy of the workbook and I can then look into the problem for you.

My email is stephenATmicrosofttraining.net

Regards

Stephen

 

Please browse our web site to find out more about
microsoft excel courses in and other Microsoft training courses.

Excel tip:

Editing a formula quickly

If you want to edit a fomrula or text quickly witin a cell instead of the formula bar, you can click either double click in the cell or press the F2 key

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard