S Oberlander
Board Regular
- Joined
- Nov 25, 2020
- Messages
- 147
- Office Version
- 365
- Platform
- Windows
The below code works perfectly.
However I prefer to name my sheet "CX Pivot" and not "CXPivot"
But if I have that space it stops by creating the pivot table with error message "Runtime error 5, invalid procedure call or argument"
Is there any way around it?
However I prefer to name my sheet "CX Pivot" and not "CXPivot"
But if I have that space it stops by creating the pivot table with error message "Runtime error 5, invalid procedure call or argument"
Is there any way around it?
VBA Code:
Sub cxp()
ActiveSheet.NAME = "CX Report"
Sheets.Add After:=ActiveSheet
ActiveSheet.NAME = "CXPivot" 'I want to name it CX Pivot
Sheets("CX Report").Select
With ActiveSheet
lastrow = .Cells(.Rows.Count, "E").End(xlUp).Row
End With
With ActiveSheet
lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
End With
Pivot2 = "R1C1:R" & lastrow & "C" & lastcol
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
Pivot2, Version:=6).CreatePivotTable _
TableDestination:="CXPivot!R3C1", TableName:="CX", DefaultVersion:=6
'Table Destination would need to be "CX Pivot!R3C1" but it doesn't work if I do that
End Sub