R
Richard D'Angelo
Is there a way to create a pivot table in VBA that can see a variable
sized range each time it is run?
Below is the macro code I recorded, trying to see how it is done. It's
the line of code with R1C1:R8888C17 that I want to change so that will
always use the current region as its database.
Any ideas?
Rich
Selection.CurrentRegion.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=
_
"Sheet1!R1C1:R8888C17").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:=Array("Object", _
"Error Description"), PageFields:=Array("Machine", "Year",
"Month")
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Error
Code")
.Orientation = xlDataField
.Caption = "Count of Error Code"
.Function = xlCount
End With
Range("A6").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Object").AutoSort _
xlDescending, "Count of Error Code"
Range("B6").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Error
Description"). _
AutoSort xlDescending, "Count of Error Code"
** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Software!
http://www.ozgrid.com/Services/excel-software-categories.htm **
sized range each time it is run?
Below is the macro code I recorded, trying to see how it is done. It's
the line of code with R1C1:R8888C17 that I want to change so that will
always use the current region as its database.
Any ideas?
Rich
Selection.CurrentRegion.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=
_
"Sheet1!R1C1:R8888C17").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:=Array("Object", _
"Error Description"), PageFields:=Array("Machine", "Year",
"Month")
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Error
Code")
.Orientation = xlDataField
.Caption = "Count of Error Code"
.Function = xlCount
End With
Range("A6").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Object").AutoSort _
xlDescending, "Count of Error Code"
Range("B6").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Error
Description"). _
AutoSort xlDescending, "Count of Error Code"
** Posted via: http://www.ozgrid.com
Excel Templates, Training, Add-ins & Software!
http://www.ozgrid.com/Services/excel-software-categories.htm **