axiehq01
12-17-2019, 09:11 AM
Hello
New to the board and I'm trying to figure out how to get this accomplished. I need to have my pivot table filter for just the dates between two dates set by 2 comboboxes.
Here's what I have right now....I'm also getting the error 'Run-Time error '438': Object doesn't support this property or method.'
Sub PivotFilterByDates()
'--Filters RowField or ColumnField to show dates between
' two dates read from cells.
Month1 = CStr(Me.ComboBox5)
Month2 = CStr(Me.ComboBox1)
Dim dtStart As Date, dtEnd As Date
Set pt1 = Sheets("Creative Pivot").PivotTables("PivotTable1")
Set pt2 = Sheets("Creative Pivot").PivotTables("PivotTable3")
Set pt3 = Sheets("Campaign Pivot").PivotTables("PivotTable1")
Set pt4 = Sheets("Campaign Pivot").PivotTables("PivotTable3")
With ActiveSheet
dtStart = Month2
dtEnd = Month1
With .pt1.PivotFields("Month")
.ClearAllFilters
.PivotFilters.Add Type:=xlDateBetween, _
Value1:=dtStart, Value2:=dtEnd
End With
End With
End Sub
New to the board and I'm trying to figure out how to get this accomplished. I need to have my pivot table filter for just the dates between two dates set by 2 comboboxes.
Here's what I have right now....I'm also getting the error 'Run-Time error '438': Object doesn't support this property or method.'
Sub PivotFilterByDates()
'--Filters RowField or ColumnField to show dates between
' two dates read from cells.
Month1 = CStr(Me.ComboBox5)
Month2 = CStr(Me.ComboBox1)
Dim dtStart As Date, dtEnd As Date
Set pt1 = Sheets("Creative Pivot").PivotTables("PivotTable1")
Set pt2 = Sheets("Creative Pivot").PivotTables("PivotTable3")
Set pt3 = Sheets("Campaign Pivot").PivotTables("PivotTable1")
Set pt4 = Sheets("Campaign Pivot").PivotTables("PivotTable3")
With ActiveSheet
dtStart = Month2
dtEnd = Month1
With .pt1.PivotFields("Month")
.ClearAllFilters
.PivotFilters.Add Type:=xlDateBetween, _
Value1:=dtStart, Value2:=dtEnd
End With
End With
End Sub