These are the configurations I want to make in the Pivot Table:
Report Filter: DESCRIPTION
Row Labels: STORE
Values: BUDGET (Sum), ACTUAL (Sum)
Filter: DESCRIPTION = TOTAL GROSS SALES
The trouble I have is implementing the Values portion of the code. The error I got when I run the code below is "Unable to set the Function property of the PivotField class". What do I need to do to get it to work?
Code: Select all
VBSTART
Sub CreatePivotTable (File,MaxRows)
xlRowField=1
xlPageField=3
xlColField=4
xlMaxRows="M"+MaxRows
xlSum=1
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(File)
objWorkBook.Sheets("All Store").Activate
objWorkBook.Sheets("All Store").Cells(13,1).Value="A"
objWorkBook.Sheets("All Store").Cells(13,2).Value="B"
objWorkBook.Sheets("All Store").Cells(13,3).Value="STORE"
objWorkBook.Sheets("All Store").Cells(13,4).Value="D"
objWorkBook.Sheets("All Store").Cells(13,5).Value="E"
objWorkBook.Sheets("All Store").Cells(13,6).Value="F"
objWorkBook.Sheets("All Store").Cells(13,7).Value="G"
objWorkBook.Sheets("All Store").Cells(13,8).Value="H"
objWorkBook.Sheets("All Store").Cells(13,9).Value="DESCRIPTION"
objWorkBook.Sheets("All Store").Cells(13,10).Value="J"
objWorkBook.Sheets("All Store").Cells(13,11).Value="BUDGET"
objWorkBook.Sheets("All Store").Cells(13,12).Value="ACTUAL"
objWorkBook.Sheets("All Store").Cells(13,13).Value="PERCENTAGE"
objWorkBook.Sheets("All Store").Range("A13:"+xlMaxRows).Select
Set objTable = objWorkbook.PivotTableWizard
Set objField = objTable.PivotFields("STORE")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("DESCRIPTION")
objField.Orientation = xlPageField
objField.CurrentPage = "TOTAL GROSS SALES"
Set objField = objTable.PivotFields("BUDGET")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.Caption = "Sum of BUDGET"
End Sub
VBEND
VBRun>CreatePivotTable,ExcelFile,MaxRows