This code creates a pivot table with the selected range and places it in a new worksheet.
VBA Code:
Sub CreatePivotTable()
Dim sourceData As Range
Dim pivotTable As PivotTable
Dim pivotSheet As Worksheet
Set sourceData = Selection
Set pivotSheet = Worksheets.Add
Set pivotTable = pivotSheet.PivotTableWizard(sourceData, TableDestination:=pivotSheet.Range("A1"))
End Sub