Excel VBA Pivot Table Values Field not populating

Hanret

New Member
Joined
Aug 25, 2013
Messages
15
I please need help converting a large set of data (not in a table) to a Pivot Table. Essentially in Col A: I have a long list of names with multiple duplications. Col B to Col AD: across are the days of a month.

For each day of the month I need to see the sum of the duplicate names in Col A.

My table looks something like this:

AngolaJan 201801 Jan02 Jan03 Jan
Peter Jones598192018
Mark Right626243323
Peter Jones421194321
Mary Black448123324

<tbody>
</tbody>

The code I have does create a Pivot Table on a new sheet as required. 'Names' is ticked in the 'Choose fields' section and is correctly displayed in the ROWS area. The tick boxes for the months do appear in the 'Choose fields' section. However, all the tick boxes are empty and the dates do not appear in the VALUES area as 'Sum of ...'.

How do I get the code to select the dates and display in the VALUES area?

This is the code I currently have:
Code:
'Insert a New Blank Worksheet for the Pivot Table
    On Error Resume Next
    Application.DisplayAlerts = False
    Worksheets("PivotTable").Delete
    Sheets.Add Before:=ActiveSheet
    ActiveSheet.Name = "ANGPivot"
    Application.DisplayAlerts = True
    
'Set references to sheets used for Pivot Table
    Set PSheet = Worksheets("ANGPivot")
    Set DSheet = Worksheets("ANG Old")


'Define Data Range (range on the 'Old' sheet)
    LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)


'Define Pivot Cache
    Set PCache = ActiveWorkbook.PivotCaches.Create _
    (SourceType:=xlDatabase, SourceData:=PRange). _
    CreatePivotTable(TableDestination:=PSheet.Cells(1, 1), _
    TableName:="ANGPivotTable")


'Insert Blank Pivot Table
    Set PTable = PCache.CreatePivotTable _
    (TableDestination:=PSheet.Cells(1, 1), TableName:="ANGPivotTable")


'Insert Row Fields
    With ActiveSheet.PivotTables("ANGPivotTable").PivotFields("Angola")
        .Orientation = xlRowField
        .Position = 1
    End With


'Insert Column Fields
    With ActiveSheet.PivotTables("ANGPivotTable").PivotFields("Dates")
        .Orientation = xlColumnField
        .Position = 1
    End With


'Insert Data Field
    With ActiveSheet.PivotTables("ANGPivotTable")
        .PivotFields ("Result")
        .Orientation = xlDataField
        .Function = xlSum
        .Name = "Broadcasts"
    End With


'Format Pivot Table and Pivot Sheet
    ActiveSheet.PivotTables("ANGPivotTable").ShowTableStyleRowStripes = True
    ActiveSheet.PivotTables("ANGPivotTable").TableStyle2 = "PivotStyleMedium9"

I'd really appreciate some help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,214,395
Messages
6,119,265
Members
448,881
Latest member
Faxgirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top