everyone,
In this pivottable I'm working on, the source data has money values and quantities. I have a filter in my pivottable in order to choose what type of data I want to see in my pivottable, whether is "V" or "Q".
My problem is that I need to format the contents of the pivottable accordingly to the type of information I'm seeing: for money values, I need to see the contents in "# ###.00 €" format; for quantity values, in "#,##0".
I already tried to use a DataRange property for the pivotfields (as you can see in the code) and even tried using NumberFormat directly on the pivotfields, but none of these worked.
Do you suggest anything to solve this?
Dim vp As Workbook
Dim type_qv As String
Dim chart_pt As PivotTable
Dim pf As PivotField
Set vp = ThisWorkbook
Set chart_pt = vp.Sheets("Chart").PivotTables("VP_table")
'this detects what type of data is being used
type_qv = vp.Sheets("Chart").Range("B2").Value
If type_qv = "Q" Then
For Each pf In chart_pt.RowFields
pf.DataRange.NumberFormat = "#,##0"
Next
End If
If type_qv = "V" Then
For Each pf In chart_pt.RowFields
pf.DataRange.NumberFormat = "# ###.00 €"
Next
End If
chart_pt.PivotFields("YourPivotField").NumberFormat = "#.##0,00 €"
– DamianDim PvtField As PivotField
and loop through all the pivotfields on your pivot table... – Damian