I am using the code below to try and create a pivot table in Excel, but it doesn't appear to be working
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Dim AllData As Range
Set AllData = selection.CurrentRegion
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=AllData).CreatePivotTable TableDestination:= _
"'[Process Data v2.xls]Pivot'!R4C1", TableName:="PivotTable3", _
DefaultVersion:=xlPivotTableVersion10
The error is with the pivot table section, and its a runtime error 5. Invalid procedure call or argument.
I have tried recording a macro and having a precise range in the script and it works, but replacing this with the 'Alldata' variable breaks it. I tried a lot of things but can't figure out why its not working
Set AllData = [A1].CurrentRegion, Remember that if any cells that are touching your data have data they will be included in Currentregion.