PDA

View Full Version : To set Date filter on pivot via input box when opening a file



Ziaullah
12-12-2018, 05:54 AM
Hi,
I am new to VBA have error while trying to set pivot table date gives error "Run Time Error 1004 'Unable to get the PivotFields property of the PivotTable class' please help me solve this issue

other than excel file contain other script with which I write in AutoOpen() so that it can do copy paste date while opening a this file also this file contain powerpivot and power query which am refreshing opening file please advise same code also not working workbook open()



Dim DateSelect As String
Dim PT As PivotTable
Dim PF As PivotField
Dim PI As PivotItem
'Dim Inputdate As Date
DateSelect = InputBox("Insert date in format mm/dd/yyyy", "Set Pivot Date", Format(Now(), "mm/dd/yyyy"))
If IsDate(DateSelect) Then
ThisWorkbook.Worksheets("PTHRPT").Select
Set PT = Worksheets("PTHRPT").PivotTables("PivotTable6")
PT.PivotFields("ActLoadEnd").ClearAllFilters
PT.PivotFields("ActLoadEnd").PivotFilters.Add Type:=xlDateEqualTo, Value1:=DateSelect
Else: MsgBox "Please insert date in correct format mm/dd/yyy", vbAbortRetryIgnore
End If

大灰狼1976
12-14-2018, 12:24 AM
Hi Ziaullah!
Attachment cannot be downloaded. Please confirm that the format or file size is correct.
I guess the problem with code is that DateSelect is a String instead of a real DateValue. of course this is just my guess you know.