Record macro does not work for identical pivot fields

GoJakie

Board Regular
Joined
Dec 1, 2007
Messages
176
Hello

I made a pivot to show Issue in Row Labels on the left and Count of Issue on the right. The same thing if I do it in macro, it does not create the pivot as both the fields Issues are identical. If I change the field Count of Issue to City (highlighted in bold in the macro given below) then everything works fine.

I wish to have the SAME field Issue and Count of Issue. What should I do. Appreciate some help here. Thanks

Here is the code
Code:
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "RAW!R1C1:R3289C8", Version:=xlPivotTableVersion12).CreatePivotTable _
        TableDestination:="Sheet16!R3C1", TableName:="PivotTable5", DefaultVersion _
        :=xlPivotTableVersion12
    Sheets("Sheet16").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable5").PivotFields("Issue")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
        "PivotTable5").PivotFields("[B]Issue[/B]"), "[B]Count of Issue[/B]", xlCount
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,

try changing
Code:
ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
        "PivotTable5").PivotFields("[B]Issue[/B]"), "[B]Count of Issue[/B]", xlCount


Into

Code:
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Issue")
        .Orientation = xlDataField
        .Position = 1
        .Function = xlcount
End With
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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