Hi
I keep getting a Runtime Error 1004 on the following Macro,
It keeps failing at the highlighted area. Anybody have any ideas?
Thanks
Dim wksPivot As Worksheet
Dim wksData As Worksheet
Dim pc As PivotCache
Dim PT As PivotTable
Set wksPivot = Sheets("RSPIVOT")
Set wksData = Sheets("Inactive RG by Recruit Type 2")
wksPivot.UsedRange.Clear
With wksData
Set pc = .Parent.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'" & .Name & "'!" & .Range("A1").CurrentRegion.Address(0, 0, xlR1C1))
Set PT = pc.CreatePivotTable(TableDestination:=wksPivot.Cells(3, 1), TableName:="")
End With
With PT
With .PivotFields("Behaviour")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Value")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Recency")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Segment")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Recruitment Summary")
.Orientation = xlColumnField
.Position = 1
End With
With .PivotFields("Recruitment Source")
.Orientation = xlColumnField
.Position = 2
End With
.AddDataField .PivotFields("No Supporters"), "Count of No Supporters", xlCount
With .PivotFields("Count of No Supporters")
.Caption = "Sum of No Supporters"
.Function = xlSum
End With
.Name = "RSPN"
End With
End Sub
I keep getting a Runtime Error 1004 on the following Macro,
It keeps failing at the highlighted area. Anybody have any ideas?
Thanks
Dim wksPivot As Worksheet
Dim wksData As Worksheet
Dim pc As PivotCache
Dim PT As PivotTable
Set wksPivot = Sheets("RSPIVOT")
Set wksData = Sheets("Inactive RG by Recruit Type 2")
wksPivot.UsedRange.Clear
With wksData
Set pc = .Parent.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'" & .Name & "'!" & .Range("A1").CurrentRegion.Address(0, 0, xlR1C1))
Set PT = pc.CreatePivotTable(TableDestination:=wksPivot.Cells(3, 1), TableName:="")
End With
With PT
With .PivotFields("Behaviour")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Value")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Recency")
.Orientation = xlPageField
.Position = 1
End With
With .PivotFields("Segment")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Recruitment Summary")
.Orientation = xlColumnField
.Position = 1
End With
With .PivotFields("Recruitment Source")
.Orientation = xlColumnField
.Position = 2
End With
.AddDataField .PivotFields("No Supporters"), "Count of No Supporters", xlCount
With .PivotFields("Count of No Supporters")
.Caption = "Sum of No Supporters"
.Function = xlSum
End With
.Name = "RSPN"
End With
End Sub