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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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
Back
Top