Results 1 to 10 of 10

Thread: Format color in pivot

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Question Format color in pivot

    Hi guys,

    I would like to format interior color of all labels of a certain pivotfield. Has anybody idea?

    Thanks.

    Boris

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Format color in pivot

    are u mentioning the pivotfield of excel? in that case u willl have to open excel (and the file) thru code and change the colors of the cells. do a search on the forums about excel automation. u will get more than 20 results.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: Format color in pivot

    Quote Originally Posted by mebhas
    are u mentioning the pivotfield of excel? in that case u willl have to open excel (and the file) thru code and change the colors of the cells. do a search on the forums about excel automation. u will get more than 20 results.
    Yes I want to do it in Excel. I am using this code. But I do not want to use a selection method

    VB Code:
    1. ActiveSheet.PivotTables("PivotTable1").PivotSelect "" & i & "[All]", xlLabelOnly _
    2.         , True
    3.     With Selection.Interior
    4.      .ColorIndex = 36
    5.         .Pattern = xlSolid
    6.         .PatternColorIndex = xlAutomatic
    7.     End With

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Format color in pivot

    i dont use the pivot tables much, in fact, i havent used it more than twice, so i dont know wxactly how a pivot table works. but there is a way to select a set of cells. if u know the range of cells (supposedly A1:C10) then u can use it this way
    VB Code:
    1. With myExcelSheet.Range("A1","C10")
    2.     .ColorIndex = 36
    3.     .Pattern = xlSolid
    4.     .PatternColorIndex = xlAutomatic
    5. End With

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: Format color in pivot

    Quote Originally Posted by mebhas
    i dont use the pivot tables much, in fact, i havent used it more than twice, so i dont know wxactly how a pivot table works. but there is a way to select a set of cells. if u know the range of cells (supposedly A1:C10) then u can use it this way
    VB Code:
    1. With myExcelSheet.Range("A1","C10")
    2.     .ColorIndex = 36
    3.     .Pattern = xlSolid
    4.     .PatternColorIndex = xlAutomatic
    5. End With
    Thanks for a try. Insteade of my previous code I have start to use this one:
    VB Code:
    1. Set pvtField = ActiveSheet.PivotTables("PivotTable1").PivotFields(j)
    2. s = pvtField.VisibleItems.Count
    3. ActiveSheet.Range(Cells(7, 1), Cells(7 + s - 1, 1)).Interior.ColorIndex = 36

    It is still not what I want, but I already missed the selection function.

  6. #6
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Format color in pivot

    in that case, u'd be better off using the selection method.
    personally, i donot have a favourite but i use the range more coz i dont need to work with selections often.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Location
    Lucenec, Slovakia
    Posts
    154

    Re: Format color in pivot

    Quote Originally Posted by mebhas
    in that case, u'd be better off using the selection method.
    personally, i donot have a favourite but i use the range more coz i dont need to work with selections often.
    I do not like to use selection too. But the first code was my first try for my problem. Now I have better solution, but I am still not satisfied with it. But it work as I wanted.

  8. #8
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Format color in pivot

    well, u may leave this thread open for somebody else (better than me) to reply or u can set this thread as resolved and try to figure something out sometime later and try to finish your work first.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format color in pivot

    Moved to Office Development

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Format color in pivot

    You can achiueve this by referring to the LabelRange property of each PivotItem in the PivotField in question.
    Here's a sample sub where I am changing the ColorIndex for each Label in the pivotField called "Name".
    VB Code:
    1. Sub BolcskeiPivotField()
    2. Dim pItem As PivotItem
    3.  
    4.     For Each pItem In ThisWorkbook.Worksheets("Sheet4").PivotTables(1).PivotFields("Name").PivotItems
    5.         pItem.LabelRange.Interior.ColorIndex = 36
    6.     Next pItem
    7. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width