XLA routines: EE_PivotArrangeColFields
Once you have created a pivot table, added the page fields, you can now add the col fields with EE_PivotArrangeColFields
Sub EE_PivotArrangeColFields(pt As PivotTable, FieldsArrayOrRange) '- as above but for col fields Dim ptColField As PivotField Dim intFld As Integer Dim arr 'http://excelexperts.com/xla-routines-eePivotArrangeColFields for updates on this sub routine For Each ptColField In pt.ColumnFields ptColField.Orientation = xlHidden Next ptColField Select Case TypeName(FieldsArrayOrRange) Case "Variant()", "String" arr = FieldsArrayOrRange Case "Range" If FieldsArrayOrRange.Cells.Count = 1 Then ReDim arr(0) arr(0) = FieldsArrayOrRange Else arr = Application.Transpose(FieldsArrayOrRange) End If Case Else End Select For intFld = LBound(arr) To UBound(arr) On Error Resume Next With pt.PivotFields(arr(intFld)) .Orientation = xlColumnField .Position = pt.ColumnFields.Count End With Err.Clear: On Error GoTo 0: On Error GoTo -1 Next intFld Erase arr Set ptColField = Nothing End Sub
»
- Nick's blog
- Login or register to post comments
- 2674 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago