how to create a dynamic pivot table using vba
lastrow = Sheet3.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lastrow = lastrow + 1
pivotrange = "ENTIRE MONTH!R1C1:R" & lastrow & "C22"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
pivotrange).CreatePivotTable TableDestination:="Pivot!R4C1", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Downtime Head")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Downtime Head")
.PivotItems("(blank)").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Site")
.Orientation = xlPageField
.Position = 1
End With
FNAME = "C:\Temp" & "\Chart4.gif"
ActiveWorkbook.Worksheets("Pivot").ChartObjects("Chart 1").Chart.Export _
Filename:=FNAME, FilterName:="GIF"
Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Row
lastrow = lastrow + 1
pivotrange = "ENTIRE MONTH!R1C1:R" & lastrow & "C22"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
pivotrange).CreatePivotTable TableDestination:="Pivot!R4C1", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Downtime Head")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Downtime Head")
.PivotItems("(blank)").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Site")
.Orientation = xlPageField
.Position = 1
End With
FNAME = "C:\Temp" & "\Chart4.gif"
ActiveWorkbook.Worksheets("Pivot").ChartObjects("Chart 1").Chart.Export _
Filename:=FNAME, FilterName:="GIF"
Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Row
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.