Littlemalky
Board Regular
- Joined
- Jan 14, 2011
- Messages
- 223
I have a bunch of data on a sheet, broken up in two portions: a top portion and a lower portion, broken by 3 empty rows. I'm using columns A:V. However, I need to create a pivot based on the top portion's data using columns E:J, the top row is a header. I used the recorder to see what the code would be and got this:
However, I can't really reference specific row numbers because I do this report on a weekly basis and the amount of data changes. The static information is the E:J part, but the i need it to select all the way down to the broken row and stop, then create a pivot on another worksheet that is already created entitled, "48 hrs".
Code:
Private Sub Macro8()
Range("E1:J1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"detail w add!R1C5:R303C10", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="48 hrs!R1C1", TableName:="PivotTable8" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("48 hrs").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("PivotTable8").PivotFields("Material")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
"PivotTable8").PivotFields("Order qty"), "Sum of Order qty", xlSum
End Sub