.Orientation = xl rowfield - Unable to set Orientation property error

Dwarakesh

New Member
Joined
Jul 24, 2014
Messages
4
I am trying to create the following pivot tables on a single sheet named Pivot. I extract data from another workbook and then run pivot for the exported data. The Highlighted red (below code) line throws 'Unable to set orientation property error'. The Department Level(1) column has varied row data as it is exported daily from another database. Please help me fix this error.

Thanks in advance!
-------------------------------------------------------------------------------------------------------------------

Sub addCache()
Dim wsNew As Worksheet


Set wsNew = Sheets.Add
wsNew.Name = "Pivot"




ThisWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, _
SourceData:="report (2)!R8C1:R60000C20").CreatePivotTable _
TableDestination:=wsNew.Name & "!R1C1", _
TableName:="TotalWorkHours"


ThisWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, _
SourceData:="report (2)!R8C1:R60000C20").CreatePivotTable _
TableDestination:=wsNew.Name & "!R21C1", _
TableName:="OvertimeHours"


With ActiveSheet.PivotTables("TotalWorkHours").PivotFields("Pay Calc Profile")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("TotalWorkHours").PivotFields("Date")
.Orientation = xlColumnField
.Position = 2
End With
With ActiveSheet.PivotTables("TotalWorkHours").PivotFields("Department(Level 1)")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("TotalWorkHours").AddDataField ActiveSheet.PivotTables( _
"TotalWorkHours").PivotFields("Total Work Hours"), "Count of Total Work Hours", _
xlCount
With ActiveSheet.PivotTables("TotalWorkHours").PivotFields( _
"Count of Total Work Hours")
.Caption = "Sum of Total Work Hours"
.Function = xlSum
End With


With ActiveSheet.PivotTables("OvertimeHours")
With .PivotFields("Pay Calc Profile")
.Orientation = xlColumnField
.Position = 1
End With


With .PivotFields("Date")
.Orientation = xlColumnField
.Position = 2
End With


With .PivotFields("Department(Level 1)")
.Orientation = xlRowField
.Position = 1
End With


.AddDataField ActiveSheet.PivotTables("OvertimeHours").PivotFields("Overtime Hours"), _
"Sum of OvertimeHours", xlSum
End With


Application.Goto Range("A1"), True
Range("B4").Select
ActiveWindow.FreezePanes = True
ActiveWindow.Zoom = 80


Columns.AutoFit






End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Oh thanks Andrew, I did that and saw that the two reports were overlapping each other. Kicking myself!

Thanks,

Dwarakesh
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top