Hi,

The data is not displaying in the below code which has written for pivot.
Please let me know where is the error is.

Thanks in advance

Sub pivot_table()
Dim pvt_ch As PivotCache
Dim pvt_tbl As PivotTable
Dim rng As Range
Set rng = ThisWorkbook.Worksheets("Formatdata").UsedRange
Set pvt_ch = ThisWorkbook.PivotCaches.Add(xlDatabase, rng)
ThisWorkbook.Worksheets("Pivot").Select
Set pvt_tbl = pvt_ch.CreatePivotTable(Worksheets("Pivot").Range("B3"))
With pvt_tbl
    .AddFields Array("Person Location", "Asset", "Reported DateTime")
End With

With pvt_tbl
    .CalculatedFields.Add "Count of Bridge Ticket Number", xlCount
    .CalculatedFields.Add "Count of Reported DateTime", xlCount
End With

With pvt_tbl.PivotFields("Count of Bridge Ticket Number")
    .Orientation = xlDataField
    .Function = xlCount
End With
With pvt_tbl.PivotFields("Count of Reported DateTime")
    .Orientation = xlDataField
 '   .Function = xlCount
End With

With pvt_tbl.DataPivotField
    .Orientation = xlColumnField
    .Position = 1
End With
With pvt_tbl
pitm_cnt = pvt_tbl.PivotFields("Person Location").PivotItems.Count
For j = 1 To pitm_cnt
        pvt_tbl.PivotFields("Person Location").PivotItems(j).ShowDetail =
False
Next
End With
Application.CutCopyMode = False
End Sub

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/discussexcel

Reply via email to