This can be done, but requires VBA to temporarily overwrite a numerical 'placeholder' value in your PivotTable with some text. To enable this, you need to set EnableDataValueEditing = True for the PivotTable. On refresh, you then do a lookup on the numerical placeholder value, and replace it with text. Convoluted, yes. Workaround, yes. But it does the trick. Note that this only 'sticks' until the next time the PivotTable is refreshed, so this code needs to be triggerred on every refresh.
Here's the code I use to do this in one of my own projects. Put this in a Standard Code Module:
Function Pivots_TextInValuesArea(pt As PivotTable, rngNumeric As Range, rngText As Range, Optional varNoMatch As Variant)
Dim cell As Range
Dim varNumeric As Variant
Dim varText As Variant
Dim varResult As Variant
Dim bScreenUpdating As Boolean
Dim bEnableEvents As Boolean
Dim lngCalculation As Long
On Error GoTo errHandler
With Application
bScreenUpdating = .ScreenUpdating
bEnableEvents = .EnableEvents
lngCalculation = .Calculation
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
varNumeric = rngNumeric
varText = rngText
pt.EnableDataValueEditing = True
'Setting this to TRUE allow users or this code to temporarily overwrite PivotTable cells in the VALUES area.
'Note that this only 'sticks' until the next time the PivotTable is refreshed, so this code needs to be
' triggerred on every refresh
For Each cell In pt.DataBodyRange.Cells
With cell
varResult = Application.Index(varText, Application.Match(.Value2, varNumeric, 0))
If Not IsError(varResult) Then
cell.Value2 = varResult
Else:
If Not IsMissing(varNoMatch) Then cell.Value2 = varNoMatch
End If
End With
Next cell
errHandler:
If Err.Number > 0 Then
If gbDebug Then
Stop: Resume
Else:
MsgBox "Whoops, there was an error: Error#" & Err.Number & vbCrLf & Err.Description _
, vbCritical, "Error", Err.HelpFile, Err.HelpContext
End If
End If
With Application
.ScreenUpdating = bScreenUpdating
.EnableEvents = bEnableEvents
.Calculation = lngCalculation
End With
End Function
And here's the result: a PivotTable with Text in the VALUES area:
Here's the 'conversion' table that tells the code what to display for each number:
I have assigned two named ranges to these, so that my code knows where to find the lookup table:
- tbl_PivotValues.TextValue
- tbl_PivotValues.NumericValue
...and here's how I trigger the Function and pass in the required arguments:
Option Explicit
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If Target.Name = "GroupView" Then Pivots_TextInValuesArea Target, [tbl_PivotValues.NumericValue], [tbl_PivotValues.TextValue]
End Sub
That code goes in the Worksheet Code Module that corresponds to the worksheet where the PivotTable is: