Solved

Issue with a Excel Pivot Table

Posted on 2013-01-30
4
239 Views
Last Modified: 2013-02-01
Hi Experts,

I have issue with attached report I like to create a pivot table for MIS porpose.

the issue I want to make fliter the product type using 2010 slicer.


Note a customer may have more than one product.
28013726-new.xlsx
0
Comment
Question by:obad62
  • 3
4 Comments
 
LVL 26

Expert Comment

by:redmondb
ID: 38835478
Hi, obad62.

That sheet is not suitable for a pivot table that includes Product Type. So I have written a macro that takes that data, reformats it into a new sheet and builds a quick pivot from that.

Before I post it here, I need to check that you're happy that the "Account Outstanding Balance" will not be include in the new sheet (and consequently not in the pivot). This is because, if it was included then it would effectively be multiplied by the number of Product Types.

Thanks,
Brian.
0
 

Author Comment

by:obad62
ID: 38838702
It ok.
0
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38839464
Thanks, obad62. Please see the code below.

I was concerned in case your original file contained some live data, so I created a test file and Netminder (one of the Mod's) kindly replaced your old version with it. Was there live data in the file?

Regards,
Brian.
Option Explicit

Sub Reformat_Data()
Dim xLast_Row As Long
Dim xLast_Col As Long
Dim xSrce As Worksheet
Dim xDest As Worksheet
Dim xRow As Long
Dim i As Long

Set xSrce = Sheets("Page1_1")

If ActiveSheet.UsedRange.Cells(1, 1).Address <> "$A$1" Then
    MsgBox ("No data in Column A and/or Row 1 - run cancelled.")
    Exit Sub
End If
xLast_Col = xSrce.UsedRange.Columns.Count
xLast_Row = xSrce.UsedRange.Rows.Count

If xLast_Row < 3 Or xLast_Col <> 43 Then
    MsgBox ("Invalid no. of rows (" & xLast_Row & ") or columns (" & xLast_Col & ") in """ & xSrce.Name & """ - run cancelled.")
    Exit Sub
End If

For i = 0 To 12
    If i = 0 Then
        Set xDest = Sheets.Add
        xSrce.Range("A2:G" & xLast_Row - 1).Copy Destination:=xDest.Range("A1")
        xDest.Range("H1") = "Product Type"
        xDest.Range("H2:H" & xLast_Row - 2) = xSrce.Range("E1").Value
    Else
        xRow = 1 + xDest.Range("A1").SpecialCells(xlLastCell).Row
        xSrce.Range("A3:D" & xLast_Row - 1).Copy Destination:=xDest.Range("A" & xRow)
        xSrce.Range("A3:C" & xLast_Row - 1).Offset(, 4 + i * 3).Copy Destination:=xDest.Range("E" & xRow)
        xDest.Range("H" & xRow & ":H" & xRow + xLast_Row - 4) = xSrce.Range("A1").Offset(, 1 + i * 3).Value
    End If
Next

xDest.Columns("D:D").Delete Shift:=xlToLeft ' ... dropped from the new sheet as it would effectively be multiplied by the number of Product Types.

xDest.Range("A1:H1").Columns.AutoFit
Range("A2").Select
ActiveWindow.FreezePanes = True

Call Build_Pivot(xDest)
    
End Sub

Sub Build_Pivot(xInput As Worksheet)
Dim xPivot    As Worksheet
Dim xLast_Row As Long

xLast_Row = xInput.UsedRange.Rows.Count
    
Set xPivot = Sheets.Add

xInput.Parent.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        xInput.Name & "!R1C1:R" & xLast_Row & "C7", Version:=xlPivotTableVersion14).CreatePivotTable _
        TableDestination:=xPivot.Name & "!R3C1", TableName:="PivotTable1", DefaultVersion _
        :=xlPivotTableVersion14

With xPivot.PivotTables("PivotTable1").PivotFields("Product Type")
    .Orientation = xlRowField
    .Position = 1
End With

xPivot.PivotTables("PivotTable1").AddDataField xPivot.PivotTables( _
        "PivotTable1").PivotFields("Deal Outstanding Balance"), _
        "Deal O/S Balance", xlSum
        
End Sub

Open in new window

0
 
LVL 26

Expert Comment

by:redmondb
ID: 38844799
Thanks, obad62.

(Was there live data in the original file?  If so, please don't do this again - information posted here is public.)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question