VBA Create Pivot Table

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:
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
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".
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,618
Messages
6,179,916
Members
452,949
Latest member
beartooth91

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