Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Change Background Color on PivotTable subtotal row

Hi.

I have a programmed pivot table, and I want to be able to change the color
on the subtotal row to gray.

It happens to be the 6th pivot item (I reference it more dynamically in the
code)...

I have:

'************
dim pvT as PivotTable
dim pvF as PivotField

set pvT = ActiveSheet.PivotTables(1)
set pvF = pvT.PivotFields(6)
'*************

If I wanted to change the displayed wording on that subtotal line from the
default, I could put in something like:

pvF.SubtotalName = "Howard the Duck"

But, how can I change the background formatting?

if I knew which cell it is ahead of time, it could be like this:

Selection.Interior.ColorIndex = 15

Thanks.
Mark

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Change Background Color on PivotTable subtotal row

I found a way to do this, though I wouldn't consider it particularly
eloquent, in that it uses On Error GoTo..

If anyone knows of a better way, please do let me know.

But, this works:

'**************
Sub test()

Dim i As Integer

On Error GoTo check_next_cell:

For i = 1 To ActiveSheet.UsedRange.Rows.Count Step 1

If Cells(i, 1).PivotCell.PivotCellType = xlPivotCellSubtotal Then

Cells(i, 1).Interior.ColorIndex = 15

End If
check_next_cell:
Next i
On Error GoTo 0

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Change Background Color on PivotTable subtotal row

' I'm using this code in "my" pivot table formating routines:

Sub Format_pivottable()
Dim R As Range
Dim i As Integer
Dim pt As PivotTable

Set R = Selection ' just for restoration at the end of the
formating

On Error Resume Next
Set pt = ActiveCell.PivotTable ' first will see whether there is
an active pivot table
If pt Is Nothing Then
Set pt = ActiveSheet.PivotTables(1) ' lets see whether there is
at least one pivot table on the sheet
If pt Is Nothing Then
MsgBox "Error: Can't find pivot table on the active sheet!"
Exit Sub
End If
End If
' ....
'....
'....
'......

If pt.RowFields.Count 1 Then
For i = pt.RowFields.Count - 1 To 1 Step -1
If pt.RowFields(i).Subtotals(1) = True Then
pt.PivotSelect "'" & pt.RowFields(i).Name &
"'[All;Total]", xlDataAndLabel, True
If pt.RowFields(i).Position = 1 Then
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 44
Else
Selection.Interior.ColorIndex = 6
End If
End If
Next i
End If

R.Select ' restore old cell selection
End Sub
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
Checkbox to change background color, font color and remove/ add bo Sara Excel Discussion (Misc queries) 2 May 1st 23 11:43 AM
how can I conditionally change font color, or background color? MOHA Excel Worksheet Functions 3 August 21st 06 06:57 PM
change background row color with change of date in a cell Urszula Excel Discussion (Misc queries) 5 May 17th 06 07:56 AM
Change of text or background color doesn't change on the screen. Susan Excel Discussion (Misc queries) 5 July 29th 05 07:18 PM
Change background color Andrew Clark Excel Discussion (Misc queries) 3 March 16th 05 04:14 AM


All times are GMT +1. The time now is 04:15 PM.

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

About Us

"It's about Microsoft Excel"