Consulting

Results 1 to 4 of 4

Thread: VBA: Filtering for a date range from 2 ComboBoxes for dates

  1. #1
    VBAX Newbie
    Joined
    Dec 2019
    Posts
    1
    Location

    VBA: Filtering for a date range from 2 ComboBoxes for dates

    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

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    I think you'll need to attach the workbook.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    I created a template using 2 combobox in the sheet. I hope it will benefit to you


    Review the sample file .
    Attached Files Attached Files

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Nice work
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •