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:
I'd really appreciate some help.
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.