How to create macro in pivot table when every time pivot table is in new sheet with changed range..

Priyank

New Member
Joined
Jun 26, 2013
Messages
1
plz anyone do help me:cry:....its very urgent...
I created a macro for creating Pivot table. But when i Run it, it shows Error.
Every time i have new data with changed Data range with different sheet range.I want to create macro such that it can be used in general for creating Pivot Table in new sheet having any name and also having any range..

I am using Ms excel 2007

The coding used by me containing Error, Plz Plz Fix it:rolleyes:

Sub Macro3()
'
' Macro3 Macro
'
'
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
DataSheet = ActiveSheet.Name
Sheets.Add
NewSheet = ActiveSheet.Name
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
DataSheet & "!A1C1:C" & FinalRow & "C12", Version:=xlPivotTableVersion10).PivotCache.CreatePivotTable
TableDestination:=NewSheet & "!R3C1", DefaultVersion:=xlPivotTableVersion10
Sheets(NewSheet).Select
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Data"), "Sum of Data", xlSum
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Patic")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Amt"), "Sum of Amt", xlSum
With ActiveSheet.PivotTables("PivotTable3").DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
ActiveCell.Select
End Sub

What to Do......???????
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

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