Group by Months in a Pivot Table

Access Beginner

Active Member
Joined
Nov 8, 2010
Messages
311
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

Below is code that will copy data from a CSV file called "Data Export" into an Excel file called "Report Template.xlsm". This works fine, the problem I'm having is that I've created a couple of pivot tables, based on this data, and it is group by month and years in the pivot tables. When the data is imported the grouping is lost. The sheet where the Pivot Table is, is called "Content Type" , the pivot table name is "PivotTable1" and the field is called "Date of Activity". The "Date of Activity" field is in the filter of the pivot table

Is there code that can be run that will group the "Date of Activity" field into years and months



Code:
  Sub CopyfromDataII()
'Clear existing data
Sheets("ISR Output by Zone").Select
    
    Range("A1:LLL100000").Select
    Selection.ClearContents
    Range("A1").Select
 
Dim ToSheet As Worksheet
Dim FromBook As String
Dim ExportFile As Variant

'Path where the Exported data is stored on the Create Zone Reports sheet in cell R37
Set ExportFile = Sheets("Create Zone Reports").Range("r37")
Set ToSheet = ActiveSheet
FromBook = ExportFile
Workbooks.Open FromBook

    
    Cells.Select
    Selection.Copy
    Windows("ISR Template  Post July 2014c.xlsm").Activate
    Sheets("ISR Output by Zone").Select
    Range("A1").Select
    ActiveSheet.Paste
    Selection.RowHeight = 15
    Range("A1").Select
    ThisWorkbook.Save   
  
    
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,203,610
Messages
6,056,296
Members
444,855
Latest member
archadiel

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