Help adding/editing a macro

Gary_H

Board Regular
Joined
Mar 18, 2015
Messages
75
Hi All,

I'm trying to make the array below perform the subsequent actions. I apologize for the size of the macro; any help would be greatly appreciated. Thank you.




Sub FixPivots()


Application.ScreenUpdating = False


'I need this array:


Sheets(Array("AnalysisMeeker", "AnalysisWolk", "AnalysisHealy", "AnalysisJones", _
"AnalysisHarris", "AnalysisMunley", "AnalysisDouglas", "AnalysisRose", _
"AnalysisGiordano", "AnalysisBugg", "AnalysisClifford", "AnalysisSullivan", _
"AnalysisCalbreath", "AnalysisMeyers")).Select




'..to perform this (the rest of the code):




ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("4/30/2015"), "Count of 4/30/2015", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("3/31/2015"), "Count of 3/31/2015", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("2/28/2015"), "Count of 2/28/2015", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("1/31/2015"), "Count of 1/31/2015", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("12/31/2014"), "Count of 12/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("11/30/2014"), "Count of 11/30/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("10/31/2014"), "Count of 10/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("9/30/2014"), "Count of 9/30/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("8/31/2014"), "Count of 8/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("7/31/2014"), "Count of 7/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("6/30/2014"), "Count of 6/30/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("5/31/2014"), "Count of 5/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("4/30/2014"), "Count of 4/30/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("3/31/2014"), "Count of 3/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("2/28/2014"), "Count of 2/28/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("1/31/2014"), "Count of 1/31/2014", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("12/31/2013"), "Count of 12/31/2013", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("11/30/2013"), "Count of 11/30/2013", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("10/31/2013"), "Count of 10/31/2013", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("9/30/2013"), "Count of 9/30/2013", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("8/31/2013"), "Count of 8/31/2013", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("7/31/2013"), "Count of 7/31/2013", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 7/31/2013")
.Caption = "Sum of 7/31/2013"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 8/31/2013")
.Caption = "Sum of 8/31/2013"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 9/30/2013")
.Caption = "Sum of 9/30/2013"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 10/31/2013")
.Caption = "Sum of 10/31/2013"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 11/30/2013")
.Caption = "Sum of 11/30/2013"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 12/31/2013")
.Caption = "Sum of 12/31/2013"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 1/31/2014")
.Caption = "Sum of 1/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 2/28/2014")
.Caption = "Sum of 2/28/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 3/31/2014")
.Caption = "Sum of 3/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 4/30/2014")
.Caption = "Sum of 4/30/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 5/31/2014")
.Caption = "Sum of 5/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 6/30/2014")
.Caption = "Sum of 6/30/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 7/31/2014")
.Caption = "Sum of 7/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 8/31/2014")
.Caption = "Sum of 8/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 9/30/2014")
.Caption = "Sum of 9/30/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 10/31/2014")
.Caption = "Sum of 10/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 11/30/2014")
.Caption = "Sum of 11/30/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 12/31/2014")
.Caption = "Sum of 12/31/2014"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 1/31/2015")
.Caption = "Sum of 1/31/2015"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 2/28/2015")
.Caption = "Sum of 2/28/2015"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 3/31/2015")
.Caption = "Sum of 3/31/2015"
.Function = xlSum
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 4/30/2015")
.Caption = "Sum of 4/30/2015"
.Function = xlSum
End With




Application.ScreenUpdating = True


End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Gary_H

Board Regular
Joined
Mar 18, 2015
Messages
75
All:

if someone can help me w/ this abbreviated version I think I'll be able to take it from there:



Sub FixPivots()

Application.ScreenUpdating = False

'I need this array:

Sheets(Array("AnalysisMeeker", "AnalysisWolk", "AnalysisHealy")).Select

'..to perform this (the rest of the code):

ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("4/30/2015"), "Count of 4/30/2015", xlCount

With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of 4/30/2015")
.Caption = "Sum of 4/30/2015"
.Function = xlSum
End With

End Sub


 
Upvote 0

Forum statistics

Threads
1,195,671
Messages
6,011,077
Members
441,581
Latest member
rp4717

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