I'm pretty sure that is possible. I don't have an exact code snippet
on hand for that but here is something that might give you an idea how
to do it.
Sub ColorContractors(Optional Acolor As Integer, _
Optional Scolor As Integer, _
Optional Hcolor As Integer, _
Optional OthersColor As Integer)
Dim pt As PivotTable
Dim pf As PivotField
Dim pfit As PivotItem
Set pt = getPivotTable
For Each pf In pt.VisibleFields
If pf.Name = "Contractor" Then
Debug.Print "found " & pf.PivotItems.Count & " pivot
items"
For Each pfit In pf.PivotItems
Select Case pfit.Name
Case "A_Company"
If Not PivotItemSelect(pf, pfit) Is Nothing Then
If Acolor <> 0 Then
Selection.Interior.ColorIndex = BHIcolor
Else
Selection.Interior.ColorIndex = 36
End If
End If
Case "B_Company"
If Not PivotItemSelect(pf, pfit) Is Nothing Then
If Scolor <> 0 Then
Selection.Interior.ColorIndex = Scolor
Else
Selection.Interior.ColorIndex = 37
End If
End If
Case "Others"
If Not PivotItemSelect(pf, pfit) Is Nothing Then
If OthersColor <> 0 Then
Selection.Interior.ColorIndex =
OthersColor
Else
Selection.Interior.ColorIndex = 5
End If
End If
Case Else
If Not PivotItemSelect(pf, pfit) Is Nothing Then
MsgBox "unknown contractor: " & _
pfit.Caption & "/" & pfit.Name & "/" &
pfit.SourceName & _
" will not be custom colored!"
End If
End Select
Next pfit
End If
Next pf
End Sub
Function PivotItemSelect(pf As PivotField, pfit As PivotItem) As Range
Err.Clear
On Error Resume Next
pfit.Parent.Parent.PivotSelect pf.Name & "[" & pfit.Name & "]",
xlDataAndLabel, True
If Err.Number <> 0 Then
Set PivotItemSelect = Nothing
Else
Set PivotItemSelect = Selection
End If
Err.Clear
On Error GoTo 0
End Function