pivot tables add

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Pivot tables - add % of row data field

Pivot tables - add % of row data field

resolvedResolved · Urgent Priority · Version 2007

Kerry has attended:
Excel VBA Intro Intermediate course

Pivot tables - add % of row data field

I have created a pivot with TotalMembers data field (function = xlsum). I now want to duplicate the field but instead of showing sum I want to show values as % of row. I also want to re-name the original field to "Customers" and the duplicate data field to "% Customers".

I know how to do this using pivots but need to do it using VBA.

I have only just been on the intermediate course so my understanding is not great.

I created the pivot using the below:

Sub CreatePivot()

Set WSD_source = Worksheets("RAW_WeeklyBehaviour") ' sheet name of source data

' Add new sheet for pivot table
Sheets.Add after:=ActiveWorkbook.Sheets(Sheets.Count) 'uses count method of sheets collection to add to end

ActiveSheet.Name = "Pivot"

'create pivot

Set rngDestination = WSD_destination.Range("A1")
Set rngSource = WSD_source.Range("A1").CurrentRegion

ActiveSheet.PivotTableWizard SourceType:=xlDatabase, _
SourceData:=WSD_source.Range("A1").CurrentRegion, tabledestination:=WSD_destination.Range("A1"), Tablename:="LostOpp"

Set PT = Sheets("Pivot").PivotTables("LostOpp")

'build pivot
With PT

.PivotFields("SearchSegmentLastWeek").Orientation = xlRowField
.PivotFields("SegmentChangeThisWeek").Orientation = xlColumnField
.PivotFields("TotalMembers").Orientation = xlDataField
.PivotFields("Total Customers").Function = xlSum

End With

With PT
.ColumnGrand = True
.RowGrand = False
.NullString = "0"
End With

End Sub

Thanks.

P.s. for trainer Stephen - please remember to email my course work to me.

RE: pivot tables - add % of row data field

Hi Kerry,

Thank you for your question and sorry about the delay in responding.

Try this code:

range("c4").select

With pvtTable
.PivotFields("Sum of Selling Price2")
.Calculation = xlPercentOfRow
.NumberFormat = "0.00%"
End With

Select a cell that contains one of the duplicate values.

Replace the field name with the one that has been generated.


I hope this helps.

Regards

Simon

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Creating custom lists

In Excel if you type in January in a cell, you can then copy this cell to replicate Febraury, MArch, April etc.

This list has come from Tools- options and Custom lists.

Therefore to save time and create your own list you can click on New (in Tools and custom list tab) and type out the lsit that you want copied quickly.

All you have to do is then type in the 1st word and you will be able to copy the rest of the list quickly.

View all Excel hints and tips


Server loaded in 0.08 secs.