PC Review


Reply
Thread Tools Rate Thread

Change Background Color on PivotTable subtotal row

 
 
mark
Guest
Posts: n/a
 
      27th Feb 2008
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

 
Reply With Quote
 
 
 
 
mark
Guest
Posts: n/a
 
      27th Feb 2008
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
 
Reply With Quote
 
minimaster
Guest
Posts: n/a
 
      28th Feb 2008
' 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox to change background color, font color and remove/ add bo Sara Microsoft Excel Misc 1 11th Nov 2008 08:17 PM
How do I change the background color and font color in word docum MarieInLaguna Microsoft Word Document Management 1 13th Aug 2008 05:02 PM
how can I conditionally change font color, or background color? =?Utf-8?B?TU9IQQ==?= Microsoft Excel Worksheet Functions 0 21st Aug 2006 06:43 PM
RE: change notepad background color/text color Jonathan Windows XP Customization 1 4th Oct 2003 08:19 AM
RE: change notepad background color/text color Jonathan Windows XP Customization 1 4th Oct 2003 12:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:11 AM.