Pivot Table VBA Help - Adding a Prompt

no1gdog

New Member
Joined
May 5, 2011
Messages
13
I am working on recording the below macro to go from Sheet to Sheet to each Pivot and Add a new data field for the current month. I'd like to be able to add a prompt when I run the macro to allow me to input the month (format would be 008.2018 for example) and everywhere in the code below where the date/month is referenced would change with that single prompt input, can someone help with that??


Sub AddNewField()
'
' AddNewField Macro
'


'
Sheets("App Services").Select
ActiveSheet.PivotTables("AppServices_1").PivotSelect "'Resouce Hours'[All]", _
xlLabelOnly + xlFirstRow, True
ActiveSheet.PivotTables("AppServices_1").AddDataField ActiveSheet.PivotTables( _
"AppServices_1").PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("AppServices_1").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Range("C218").Select
ActiveSheet.PivotTables("AppServices_2").AddDataField ActiveSheet.PivotTables( _
"AppServices_2").PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("AppServices_2").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Sheets("EU_ASIA Apps").Select
Range("C159").Select
ActiveSheet.PivotTables("EUASIA_1").AddDataField ActiveSheet.PivotTables( _
"EUASIA_1").PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("EUASIA_1").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Range("C181").Select
ActiveSheet.PivotTables("EUASIA_2").AddDataField ActiveSheet.PivotTables( _
"EUASIA_2").PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("EUASIA_2").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Sheets("FORCE_GIC_IG_PCS").Select
Range("C207").Select
ActiveSheet.PivotTables("FORCEGIC_1").AddDataField ActiveSheet.PivotTables( _
"FORCEGIC_1").PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("FORCEGIC_1").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Range("C235").Select
ActiveSheet.PivotTables("FORCEGIC_2").AddDataField ActiveSheet.PivotTables( _
"FORCEGIC_2").PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("FORCEGIC_2").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Sheets("GBS").Select
Range("C171").Select
ActiveSheet.PivotTables("GBS_1").AddDataField ActiveSheet.PivotTables("GBS_1"). _
PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("GBS_1").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Range("C199").Select
ActiveSheet.PivotTables("GBS_2").AddDataField ActiveSheet.PivotTables("GBS_2"). _
PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("GBS_2").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Sheets("IIS").Select
Range("C169").Select
ActiveSheet.PivotTables("IIS_1").AddDataField ActiveSheet.PivotTables("IIS_1"). _
PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("IIS_1").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
ActiveSheet.PivotTables("IIS_2").PivotSelect "PPMC Name", xlButton, True
Range("C197").Select
ActiveSheet.PivotTables("IIS_2").AddDataField ActiveSheet.PivotTables("IIS_2"). _
PivotFields("008.2018"), "Count of 008.2018", xlCount
With ActiveSheet.PivotTables("IIS_2").PivotFields("Count of 008.2018")
.Caption = "Sum of 008.2018"
.Function = xlSum
End With
Sheets("IIS").Select
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
One additional item needed: When I re-run the macro, it's putting the new field as the last field when I recorded it to go before the field called "YTD". So I will be all the monthly data fields and YTD at the end. Please tell me what I can add to the code to make it place the new field I am selecting before YTD so I can have Month 1 through (new field) and then YTD in my pivot.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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