PDA

View Full Version : VBA: Filtering for a date range from 2 ComboBoxes for dates



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

p45cal
12-17-2019, 07:13 PM
I think you'll need to attach the workbook.

kadrl
12-19-2019, 12:07 PM
I created a template using 2 combobox in the sheet. I hope it will benefit to you

https://www.youtube.com/watch?v=4ElNQAof1nY

Review the sample file .

paulked
12-19-2019, 12:53 PM
Nice work :thumb