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:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Angola[/TD]
[TD]Jan 2018[/TD]
[TD]01 Jan[/TD]
[TD]02 Jan[/TD]
[TD]03 Jan[/TD]
[/TR]
[TR]
[TD]Peter Jones[/TD]
[TD]598[/TD]
[TD]19[/TD]
[TD]20[/TD]
[TD]18[/TD]
[/TR]
[TR]
[TD]Mark Right[/TD]
[TD]626[/TD]
[TD]24[/TD]
[TD]33[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]Peter Jones[/TD]
[TD]421[/TD]
[TD]19[/TD]
[TD]43[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]Mary Black[/TD]
[TD]448[/TD]
[TD]12[/TD]
[TD]33[/TD]
[TD]24[/TD]
[/TR]
</tbody>[/TABLE]

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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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