Pivot Table

xtinct

New Member
Joined
Sep 11, 2006
Messages
48
how to use VBA to create a pivot table for the 2 columns?
pivot1.jpg


and then from the pivot table to generate a line chart similar to
pivot2.jpg


but with an additional constant line at Y :0.5 as an average?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

MarkAndrews

Well-known Member
Joined
May 2, 2006
Messages
1,963
Something like

Code:
    Columns("A:B").Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!C1:C2").CreatePivotTable TableDestination:="", TableName:= _
        "PivotTable1"
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    ActiveSheet.PivotTables("PivotTable1").SmallGrid = False
    ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Int fn 1"
    ActiveSheet.PivotTables("PivotTable1").PivotFields("overlay fn").Orientation = _
        xlDataField
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("overlay fn")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable1").PivotSelect "'Int fn 1'[All;Total]", _
        xlDataAndLabel
    Selection.Delete
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Int fn 1")
        .PivotItems("(blank)").Visible = False
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("overlay fn")
        .PivotItems("(blank)").Visible = False
    End With
    Application.CommandBars("PivotTable").Visible = False
    Range("B5").Select
    Charts.Add
    ActiveChart.SetSourceData Source:=Sheets("Sheet4").Range("B5")
    ActiveChart.Location Where:=xlLocationAsNewSheet
    ActiveChart.SeriesCollection(1).Select
    ActiveChart.ChartType = xlLineMarkersStacked
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,026
Messages
5,856,928
Members
431,838
Latest member
mydayisgood

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top