Adjusting Pivot Table Data Source

CHELLY

New Member
Joined
Mar 1, 2016
Messages
2
How do I change the data range in a pivot table? I used recorded macro to get this information. I need the Source Data row to automatically adjust the Source Data (row/columns)

Below is my code. text is in red….

Range("A1").Select

On Error Resume Next

mylastrow = Cells.Find("*", [a1], , , xlByRows, xlPrevious).Row

mylastcol = Cells.Find("*", [a1], , , xlByColumns, xlPrevious).Column

mylastcell = Cells(mylastrow, mylastcol).Address

Data_range = "A1:" & mylastcell

Range(Data_range).Select

'Sheets("DATA").Select

Sheets.Add

ActiveSheet.Name = "Summary"

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

"DATA!R1C1:R534C15", Version:=xlPivotTableVersion14).CreatePivotTable _

TableDestination:="Summary!R3C1", TableName:="PivotTable1", DefaultVersion _

:=xlPivotTableVersion14




Sheets("Summary").Select

Cells(3, 1).Select

With ActiveSheet.PivotTables("PivotTable1").PivotFields("PGM")

.Orientation = xlRowField

.Position = 1

End With

With ActiveSheet.PivotTables("PivotTable1").PivotFields("TYPE")

.Orientation = xlRowField

.Position = 2

End With

With ActiveSheet.PivotTables("PivotTable1").PivotFields("BCOC")

.Orientation = xlRowField

.Position = 3

End With

ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _

"PivotTable1").PivotFields("I_INVC_PAY_AMT"), "Sum of I_INVC_PAY_AMT", xlSum

With ActiveSheet.PivotTables("PivotTable1")

.InGridDropZones = True

.RowAxisLayout xlTabularRow

End With



Thanks!!!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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