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!!!
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Watch MrExcel Video

Forum statistics

Threads
1,122,481
Messages
5,596,396
Members
414,063
Latest member
N_Bates

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
Top