Command Button Macro for Pivot Tables

Mikeykt

New Member
Joined
Feb 10, 2011
Messages
47
Hi

I'm trying to create a Command Button macro for a Pivot tbale.

There are five sheet on the workbook:
1. Front Sheet
2. RSPIVOT
3. Inactive RG by Recruit type 2
4. AGPIVOT
5. Inactive RG by Acorn Code 2

The Command buttons are on the front sheet, when they are clicked they should run the following vba code, yet they no longer work. I can't see the obvious error, can anyone help?

Sub RSPivotNum()
'
' RSPivotNum Macro
'
'
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


Sorry

it keeps failing at this stage:

Set PT = pc.CreatePivotTable(TableDestination:=wksPivot.Cells(3, 1), TableName:="")
<!-- / message -->
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Sorry

it keeps failing at this stage:

Set PT = pc.CreatePivotTable(TableDestination:=wksPivot.Cells(3, 1), TableName:="")
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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