Stop searching. Start learning and developing your excel skills.
Macro
VBA
Formula
Function
Shortcut
Tricks

» » VBA To Change Pivot Table Fields Format

VBA To Change Pivot Table Fields Format

July 19, 2020 |
By just a single click, we can change pivot table field value format to any format.


Codes to change pivot table field default format to number format:

    Dim pvName As String, pvfName As String
    
    pvName = ActiveCell.PivotTable.Name
    pvfName = ActiveCell.PivotField.Name
    
    With ActiveSheet.PivotTables(pvName).PivotFields(pvfName)
        .NumberFormat = "#,##0_);[Red](#,##0)"
    End With

Codes to change pivot table field default format to percentage format:

    Dim pName As String, pfName As String
    
    pName = ActiveCell.PivotTable.Name
    pfName = ActiveCell.PivotField.Name
    
    With ActiveSheet.PivotTables(pName).PivotFields(pfName)
        .NumberFormat = "0%;[Red]-0%"
    End With
Note: Adjust .NumberFormat to your desire format.

No comments:

Post a Comment