Hello to all of you!
I have this PivotTable PivotTable1.jpg where I need to count the number of dates for each month for certain customer ( In the example: 6 dates in the month "1" of the Customer named "Modular Tops, S. de R.L.". So far i have tried with this code:
Sub
CalculateNoPayments() ' columna H (8) OK
Dim C, I As Integer
Dim CTE, TD As String
Dim WSD1 As Worksheet
Dim WSD2 As Worksheet
'
'
Set WSD1 = Worksheets("BASE")
Set WSD2 = Worksheets("Days")
CTE = WSD1.Range("AB1").Text
TD = "TD3"
WSD2.PivotTables(TD).PivotFields("Razon social").PivotItems(CTE).ShowDetail = True "Customer detail"
WSD2.PivotTables(TD).PivotFields("mes").ShowDetail = True "Month Field detail"
On Error Resume Next
For I = 1 To 12
WSD2.PivotTables(TD).PivotFields("mes").PivotItems(I).DataRange.Select 'Even tried LabelRange, same result :(
C = WSD2.PivotTables(TD).PivotFields("mes").PivotItems(I).DataRange.Count
'Inserta valor de numero de pagos en tabla Base "Inserts count on Sheet "BASE" for each month
If C > 0 Then
WSD1.Cells(I + 3, 8).Value = C - 1
C = 0
Else
WSD1.Cells(I + 3, 8).Value = "-"
End If
Next I
On Error GoTo 0
WSD2.PivotTables(TD).PivotFields("mes").ShowDetail = False
WSD2.PivotTables(TD).PivotFields("Razon social").PivotItems(CTE).ShowDetail = False
WSD1.Select
Range("H4:H21").Select
Selection.Style = "Comma"
Selection.NumberFormat = "_-* #,##0_-;-* #,##0_-;_-* ""-""??_-;_-@_-"
Range("A1").Select
End Sub
So far without any luck (I´m using Excel 2007). I have include the excel file with the data.
¿Could you help me find what I am missing? Thank you all in advance!
Regards
José Luis
Bookmarks