Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default percent of row in subtotal range

I want to show the percent of column a row has for the subtotal in my pivot
table. See example below. I have figured out how to do this if I use the
option to have subtotals appear a the bottom and use a function just outside
the pivot table to the right. However, I prefer my subtotals at the top and
there is no text in the top row like in the bottom that says "XXX subtotal".
I started to write a macro that would do this but I can't figure out how to
determine if a row is a subtotal row. Any ideas on how to determine if a
particular row is a subtotal row?

I was hoping that activecell.pivotcell.pivotcelltype would tell me but it
gives me the same value for both a data row and a subtotal row. I even
thought about looking for the format style when I applied a formating style
to the table. IE. if it's bold it's a subtotal field. But that did not
work either.

Any ideas?
Blue 80
item1 50 62.5% 50/80
item2 20 25% 20/80
item3 10 12.5% 10/80
Red
item4
item5
Gren
item6
item7

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default percent of row in subtotal range

I finally figured out how to accomplish my goal and I thought I would post
the answer here as well.


What this macro does is one column to the right of the pivot table it will
insert the percent of that row to the subtotal and not grand total, when you
have subtotals placed at the top.

The trick to all of this is determining the subtotal row in the pivot table.
I did this by looking at labelrange.address, getting the row number for the
label row, then comparing it to the row I am currently inserting the
percentage for.


ActiveCell.PivotCell.RowItems.Item(1).LabelRange.A ddress,
Sub PivotTableCreateSubTotals()
Dim pitem As Excel.PivotItem
Dim pvt As Excel.PivotTable
Dim r As Range
Dim col As Range
Dim i As Integer
Dim s() As String

Set pvt = ActiveSheet.PivotTables(1)

Set r = pvt.RowRange
Set col = pvt.ColumnRange



For i = 2 To r.Rows.Count - 1
r.Cells(i, col.Columns.Count + 1).Select
s = Split(ActiveCell.PivotCell.RowItems.Item(1).LabelR ange.Address,
"$")
If s(2) = ActiveCell.Row Then
ActiveCell.Offset(0, 1).Value = ""
Else
ActiveCell.Offset(0, 1).Value = ActiveCell.Value / Cells(s(2),
ActiveCell.Column)
End If
Next


End Sub

"Brady" wrote:

I want to show the percent of column a row has for the subtotal in my pivot
table. See example below. I have figured out how to do this if I use the
option to have subtotals appear a the bottom and use a function just outside
the pivot table to the right. However, I prefer my subtotals at the top and
there is no text in the top row like in the bottom that says "XXX subtotal".
I started to write a macro that would do this but I can't figure out how to
determine if a row is a subtotal row. Any ideas on how to determine if a
particular row is a subtotal row?

I was hoping that activecell.pivotcell.pivotcelltype would tell me but it
gives me the same value for both a data row and a subtotal row. I even
thought about looking for the format style when I applied a formating style
to the table. IE. if it's bold it's a subtotal field. But that did not
work either.

Any ideas?
Blue 80
item1 50 62.5% 50/80
item2 20 25% 20/80
item3 10 12.5% 10/80
Red
item4
item5
Gren
item6
item7

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
Conditional Formatting by percent range Sandusky Excel Discussion (Misc queries) 3 May 14th 23 11:44 AM
subtotal by a range gls858 New Users to Excel 4 April 7th 09 10:57 PM
Pivottable: Show value as a percent of Subtotal Ted M H Excel Discussion (Misc queries) 10 May 10th 08 04:57 AM
Formatting a number to look like a Percent without a percent sign David Iacoponi Excel Discussion (Misc queries) 2 September 15th 05 06:35 PM
Percent Format without Percent Sign jstrater Excel Programming 1 April 29th 04 07:28 AM


All times are GMT +1. The time now is 09:08 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"