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
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