PDA

View Full Version : Need a little help please



realitydrm
03-27-2017, 05:00 PM
I run the same reports everyday and would like to use a generic VBA code that selects all my data and creates the pivot table. I've recorded the MACRO:

- I need the data range selected automatically to be allow any data amount
- I need the data range to be selected automatically
- The sheet should not matter
- Finally I would like to name the sheet


Sheets.Add
ActiveWorkbook.Worksheets("Sheet1").PivotTables("PivotTable26").PivotCache. _
CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable27" _
, DefaultVersion:=xlPivotTableVersion15
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable27").PivotFields("Date Opened")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable27").PivotFields("Date Opened")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable27").PivotFields("Queue")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable27").PivotFields("Sub Queue")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable27").PivotFields("Status")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable27").AddDataField ActiveSheet.PivotTables( _
"PivotTable27").PivotFields("Source"), "Count of Source", xlCount
With ActiveSheet.PivotTables("PivotTable27").PivotFields("Queue")
.PivotItems("(blank)").Visible = False
End With
End Sub

Paul_Hossler
03-27-2017, 05:45 PM
I added
... tags around your code. You can use the [#] icon to do that

It makes the macro easier to read

Can you attach a sample workbook with the data and what you want the PT to look like?

realitydrm
03-28-2017, 06:18 PM
Due to the sensitive nature of the data I cannot.

Paul_Hossler
03-28-2017, 08:58 PM
Put in fake data so we can see the structure and formats at least