Is there a way we can rename pivot table name on basis of active cell?
For example, I have a pivot starting from cell A1 and I want to copy that pivot to cell F1 and rename it using VBA without using reference PivotTables("PivotTable1").
Sub Demo()
Dim pvt As PivotTable
On Error GoTo ErrHandle:
Set pvt = ActiveCell.PivotTable
pvt.TableRange2.Copy Range("F1")
With Range("F1").PivotTable
.Name = "New Name"
End With
ErrHandle:
If Err.Number <> 0 Then
MsgBox "You must select pivot table range. Or you must change destination range to avoid range overlap"
End If
End Sub