I am trying to create a pivot using below code, however I am receiving error,
"Invalid Procedure call or argument"
Can someone please help.
Here is my code:
Sub Creatingquerypivot()
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String
Dim Pf As PivotField
'Create Pivot Cache from Source Data
Set pvtCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=Sheets("Queries").Name & "!" & Sheets("Queries").Range("A3").CurrentRegion.Address)
'Create a new worksheet
Set sht = Sheets.Add
sht.Name = "Queries Summary"
'Where do you want Pivot Table to start?
StartPvt = sht.Name & "!" & sht.Range("A3").Address(ReferenceStyle:=xlA1)
'Create Pivot table from Pivot Cache
- Set pvt = pvtCache.CreatePivotTable( _
TableDestination:=StartPvt, _
TableName:="QueriesSummary")
'To add fields to the pivot table
Set Pf = pvt.PivotFields("Folder")
Pf.Orientation = xlRowField
Set Pf = pvt.PivotFields("Category")
Pf.Orientation = xlRowField
Set Pf = pvt.PivotFields("Received")
Pf.Orientation = xlDataField
TableDestinationexpects aRangeobject, not aString."Not working"is not a helpful description. Can you edit your question with the revised code you are using, and the error message?TableDestinationexpects a Variant - does not need to be a Range object, or recorded macros from creating a pivot table would not work - they always use the "range string" apporach.