Giriraj Desai
Member
Hi,
Could you please help me , I have recorded a macros to get two different pivot table from two different sheets and the pivot is made in one single sheet.
when I run the macros the first pivot is getting correctly for the second one I am getting a run time error 5 "invalid argument". i have tried could not able to achieve it
can you please help me and below is the recorded syntex.
Sub Macro1()
'
' Macro1 Macro
'
'
Columns("A:K").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"'sap Vat report - Copy'!A:K", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion12
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("DocumentNo")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(" Tax base amount"), _
"Count of Tax base amount", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of Tax base amount")
.Caption = "Sum of Tax base amount"
.Function = xlSum
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Rave report").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
""This is part where I am getting error"
Run time error 5 "Invalid procedure call argument".
----------------------------------------------------------------------
Columns("B:X").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"'Rave report'!B:X", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="'[Pivot 2.xlsx]Sheet1'!R3C9", TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion12
-------------------------------------------------------------------------------------
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PO/BILLING")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("INVOICE VALUE"), "Count of INVOICE VALUE", xlCount
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Count of INVOICE VALUE")
.Caption = "Sum of INVOICE VALUE"
.Function = xlSum
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Range("E1").Select
End Sub
Many thanks in advance for your help!!!
Regards
Giriraj
Could you please help me , I have recorded a macros to get two different pivot table from two different sheets and the pivot is made in one single sheet.
when I run the macros the first pivot is getting correctly for the second one I am getting a run time error 5 "invalid argument". i have tried could not able to achieve it
can you please help me and below is the recorded syntex.
Sub Macro1()
'
' Macro1 Macro
'
'
Columns("A:K").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"'sap Vat report - Copy'!A:K", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion12
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("DocumentNo")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(" Tax base amount"), _
"Count of Tax base amount", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"Count of Tax base amount")
.Caption = "Sum of Tax base amount"
.Function = xlSum
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Rave report").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 14
ActiveWindow.ScrollColumn = 13
ActiveWindow.ScrollColumn = 12
ActiveWindow.ScrollColumn = 11
ActiveWindow.ScrollColumn = 10
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 8
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
""This is part where I am getting error"
Run time error 5 "Invalid procedure call argument".
----------------------------------------------------------------------
Columns("B:X").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"'Rave report'!B:X", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="'[Pivot 2.xlsx]Sheet1'!R3C9", TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion12
-------------------------------------------------------------------------------------
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PO/BILLING")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("INVOICE VALUE"), "Count of INVOICE VALUE", xlCount
With ActiveSheet.PivotTables("PivotTable2").PivotFields( _
"Count of INVOICE VALUE")
.Caption = "Sum of INVOICE VALUE"
.Function = xlSum
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Range("E1").Select
End Sub
Many thanks in advance for your help!!!
Regards
Giriraj