Set Pivot date based off input box answer.

Nutterhead

New Member
Joined
Apr 25, 2017
Messages
27
Hi again,

I'm a self teaching newbie and am having issues with the workbook I'm creating. I'm trying to set a pivot table date based on the answer given in an input box but I'm not having much luck. Below is what I have come up with, any help would be greatly appreciated.

Sub Change_Pivot_Filter()
Dim ans As String, lr As Long
startagain:
ans = InputBox("Enter Report Date" & vbNewLine & "MM/DD/YYYY", "Date")
If StrPtr(ans) = inputboxcancel Then
Exit Sub
End If
If ans Like "##/##/####" Then
bInputOK = True
Else
MsgBox ("Wrong Date Format" & vbNewLine & "Please Reenter Date as MM/DD/YYYY")
GoTo startagain
End If

'Sets Date
Dim WS As Excel.Worksheet
Dim myPivot As Excel.PivotTable
Dim myPivotField As Excel.PivotField
Set WS = ActiveSheet
For Each myPivot In WS.PivotTables
Set myPivotField = Nothing
On Error Resume Next
Set myPivot.PivotFields("Date").CurrentPage = ans
Next myPivot
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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