Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default relation between fields in PivotTable

Thanks a lot - it gave me an idea, I will "warp" your code and use you idea
for me.
Once more time THANKS A LOT !!!

Vlado

"minimaster" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivottable Sum of fields. Saviz Excel Discussion (Misc queries) 1 July 17th 08 12:10 PM
PivotTable - Clear all data fields Bradley Searle[_2_] Excel Programming 0 March 17th 08 12:24 PM
pivottable calculated fields HelpAl Excel Discussion (Misc queries) 3 December 8th 05 10:18 PM
PivotTable-Fields Page Andrea Excel Programming 1 December 15th 04 02:08 PM
pivottable page fields Grant Excel Programming 1 October 16th 04 09:09 PM


All times are GMT +1. The time now is 05:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"