tryharder1997
New Member
- Joined
- Jan 2, 2019
- Messages
- 2
Hi, I'm fairly new to writing code and trying to write a macro that will sort my pivot table by either a month, or by a subtotal for a group. The months are just grouping for days and these months also fall into another grouping done by adding another row field not grouping in the pivot table. The only issue is that sometimes the data in pivot table changes so using the pivotline(#) reference is hard.
This is the pivot lines code, but would rather i referred to the name of a column sort of like in GetPivotData.
any help is much appreciated.
Code:
Sub macro5()'
Sheets("Pivot").Select
Dim score As Integer
score = Range("B1").Value
If score = "0" Then
ActiveSheet.PivotTables("PivotTable1").PivotFields("Sold to #").AutoSort _
xlDescending, "YTD-2018-NOV"
Else
ActiveSheet.PivotTables("PivotTable1").PivotFields("Billed to #").AutoSort _
xlDescending, "YTD-2018-NOV"
End If
Sheets("Report").Select
End Sub
Code:
Sub Macro4()
'
' Macro4 Macro
'
'
Sheets("Pivot").Select
Dim score As Integer
score = Range("B1").Value
If score = "0" Then
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable1").PivotFields("Billed to #").AutoSort _
xlDescending, "Sum of CUR", ActiveSheet.PivotTables("PivotTable1"). _
PivotColumnAxis.PivotLines(19), 1
Else
Application.CutCopyMode = False
ActiveSheet.PivotTables("PivotTable1").PivotFields("Billed to #").AutoSort _
xlDescending, "Sum of CUR", ActiveSheet.PivotTables("PivotTable1"). _
PivotColumnAxis.PivotLines(20), 1
End If
Sheets("Report").Select
End Sub
any help is much appreciated.