Pivot Table and Macro. Row disapear.

jbesclapez

Active Member
Joined
Feb 6, 2010
Messages
275
Hi Mr Excel!

I have a macro that i recorded to do a pivot table.
When i run it, it doesnot put the rows. I dont understand because when i record i do put them.

Here is the code below :
Code:
Sub Macro9()
Worksheets.Add().Name = "DynTab"
'Create a dynamic table on the DynTab sheet create before in Cell A4

    Sheets("Attachments-PO").Select
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Attachments-PO!R1C1:R95C6", Version:=xlPivotTableVersion10). _
        CreatePivotTable TableDestination:="DynTab!R4C1", TableName:="PivotTable5" _
        , DefaultVersion:=xlPivotTableVersion10
    Sheets("DynTab").Select
    Cells(4, 1).Select
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("PO")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
        "PivotTable5").PivotFields("PO"), "Count of PO", xlCount
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("UnitCC")
        .Orientation = xlPageField
        .Position = 1
    End With
    Columns("A:A").ColumnWidth = 24.14
    Cells.Select
    Selection.RowHeight = 13.5
    Range("C1").Select

End Sub

Thanks for your help
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I think that the existing PO field is being moved from the row area to the data area. Changing the order of field creation worked for me:

Code:
Sub Macro9()
Worksheets.Add().Name = "DynTab"
'Create a dynamic table on the DynTab sheet create before in Cell A4
    Sheets("Attachments-PO").Select
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Attachments-PO!R1C1:R95C6", Version:=xlPivotTableVersion10). _
        CreatePivotTable TableDestination:="DynTab!R4C1", TableName:="PivotTable5" _
        , DefaultVersion:=xlPivotTableVersion10
    Sheets("DynTab").Select
    Cells(4, 1).Select
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
        "PivotTable5").PivotFields("PO"), "Count of PO", xlCount
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("PO")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("UnitCC")
        .Orientation = xlPageField
        .Position = 1
    End With
    Columns("A:A").ColumnWidth = 24.14
    Cells.Select
    Selection.RowHeight = 13.5
    Range("C1").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,724
Messages
6,126,477
Members
449,315
Latest member
misterzim

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