I am new to VBA and I am trying to create a macro to which I will make a button out of to make a Pivot Table from data that I paste into a certain sheet.
The code below is from a macro that I tried to produce step-by-step of how I want the code to run.
I am selecting certain data (Columns A:G), then pasting that data into another sheet and then creating a blank table.
My code:
Sub Macro2()
'
' Macro2 Macro
'
'
Cells.Select
Range("A672198").Activate
Application.CutCopyMode = False
Selection.Copy
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet2!R1C1:R1048576C7", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Sheet11!R3C1", TableName:="PivotTable6", DefaultVersion _
:=xlPivotTableVersion15
Sheets("Sheet11").Select
Cells(3, 1).Select
End Sub
The issue comes from:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet2!R1C1:R1048576C7", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Sheet11!R3C1", TableName:="PivotTable6", DefaultVersion _
:=xlPivotTableVersion15
with an error message of:
Run-time error '5': invalid procedure call or argument
I have tried researching how to make a basic macro to create a blank pivot table of my data but I can't seem to figure it out.
I have also looked at many posts from this site and nothing really helped. I tried referencing this post but no luck.
I am using Microsoft Excel 2013*