Public Sub CreateCompletePivotTable()
Dim wb As Workbook
Dim pt As PivotTable
'On Error GoTo errorhandler
'open the workbook.
Set wb = Workbooks.Open("c:vandanaadvptexamplesVideoStoreRawData.xls")
'create the pivottable and get a reference to it.
Set pt = Worksheets("Sheet1").PivotTableWizard(SourceType:=xlDatabase, SourceData:=Range("Sheet1!A4:C28"), tabledestination:=Range("Sheet2!F2"))
' Add row and column fields
pt.AddFields RowFields:="Store", ColumnFields:="Category"
'Add data Field.
pt.AddDataField pt.PivotFields("Titles"), "Total Titles"
'endofsub:
'Exit Sub
'errorhandler:
'If Err.Number = 5 Or Err.Number = 9 Then
'MsgBox "The file could not be found"
'ElseIf Err.Number = 1004 Then
'MsgBox "There is already a pivot table on that location"
'Else
'MsgBox "Error" & Err & " - " & Err.Description
'End If
'Resume endofsub
End Sub