excel macro to create pivottable

wally32

New Member
Joined
Mar 7, 2011
Messages
29
im looking to make my job that bit quicker by introducing a macro to help analysis spreadsheets within a workbook.
within the workbook there will be 12 worksheets (one for each month), where i be analysing some data through a pivottable. creating the pivottable is fine. the information i be looking to analyse will be in column c - h and number of rows maybe different from month to month.
i recorded a macro from start of highlighting cells to creating the final pivottable. when i try the same macro for a different month is comes up with few errors. the macro code i recorded is below
ub Macro2()
'
' Macro2 Macro
' Macro recorded 17/03/2011 by waltek
'
'
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'Feb 2011'!C3:C7").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Region")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Score"), "Count of Score", xlCount
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Score")
.Orientation = xlColumnField
.Position = 1
End With
Sheets("Feb 2011").Select
End Sub

when i run it for the month of march, it comes up with a run time 1004
saying UNABLE TO GET PIVOTFIELDS PROPERTY OF THE PIVOT TABLE CLASS

tried to find what this error means, but couldnot find any solotions

thanks
 
You can't combine the 2 procedures. Surely you don't want to create a pivot table each time there is a change in a cell in column C?
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
basically just need column C (region column) to format automatically when user enters the information. would use the conditonlly format option in excel but you can only do 3 formats, where as i need 5.

the pivottable will only be created at the end of each month.

so for the worksheet there be 2 macros, one just to format cells daily and one to analysis info at the end of month.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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