Creating Pivot Table with Distinct Count using VBA

前端 未结 3 478
南旧
南旧 2021-01-15 23:19

I am trying to create a pivot table using Excel 2013 VBA with DISTINCT COUNT as a value field.

I understand that if you create the pivot table manually, you have to

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-16 00:11

    I just recorded creating a pivot table that uses the option "Add this data to the Data Model". And created a Distinct count field. I had to add the count first, then change it to Distinct. I modified it for your worksheet and pivot table names. Add the measure count of appno, then modify to Distinct. Here is the distinct count section.

    With Worksheets("PivotTable").PivotTables("SalesPivotTable").PivotFields( _
        "[Measures].[Count of AppNo]")
        .Caption = "Distinct Count of AppNo"
        .Function = xlDistinctCount
    End With
    

提交回复
热议问题