Solved

Issue with a Excel Pivot Table

Posted on 2013-01-30
4
237 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article will show you how to use shortcut menus in the Access run-time environment.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

770 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