Making a simple Pivot Using VBA

DigvijaySal

New Member
Joined
May 15, 2014
Messages
1
Hello All,

I created the below VBA for making a pivot run in macros,

It show - Run-time error '5', Invaild Procedure call or argument for the below bold text, can anyone help me figure out my error and how to correct the same, Thanks a Ton!

Sub Pivotmacro()
'
' Pivotmacro Macro
'


'
FR = Cells(Rows.Count, 1).End(xlUp).Row
DataSheet = ActiveSheet.Name
Sheets.Add
NewSheet = ActiveSheet.Name
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
DataSheet & "!R1C1:R" & FR & "C45", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:=NewSheet & " !R3C1", TableName:="PivotTable4", DefaultVersion _
:=xlPivotTableVersion14
Sheets("NewSheet").Select
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
"PivotTable4").PivotFields("Complaint #"), "Count of Complaint #", xlCount
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Region")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Complaint Status")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable4").PivotFields("Complaint Status"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("PivotTable4").PivotFields("Complaint Status")
.PivotItems("Pre-closure").Visible = False
.PivotItems("Re-open").Visible = False
End With
ActiveSheet.PivotTables("PivotTable4").PivotFields("Complaint Status"). _
EnableMultiplePageItems = True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
i may be wrong but when i tried to do this I found the references had to be in R1C1 format throughout and you seem to have mixed them for the sourcedata
i used
Code:
intNumRows = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
SourceColumn = "!R1C" & Selection.Column & ":R" & intNumRows & "C" & Selection.Column

and then

Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    SourceSheet & SourceColumn, Version:=xlPivotTableVersion10).CreatePivotTable _
    TableDestination:=SummarySheet & "!R3C2", TableName:="Pvt" & PivotName, DefaultVersion _
    :=xlPivotTableVersion10
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,859
Members
449,472
Latest member
ebc9

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