Setting Dynamic Dates for Pivot Table grouping

  • Hi guys,


    Where am I going wrong here.


    I am trying to set dynamic dates for my Pivot Table Group.


    Code
    Dim StartDate As Date
    Dim EndDate As Date
    Dim PT As PivotTable
    StartDate = Range("M1").Value
    EndDate = Range("N1").Value
        Set PT = ActiveSheet.PivotTables("PivotTable3")
        [B]PT.DateRange.Group Start:=CLng(StartDate), End:=CLng(EndDate), By:=1, Periods:=Array(False, False, False, False, True, False, True)[/B]
        ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
    End Sub


    I am getting a runtime error: 428 "Object doesn't support this property or method" and it highlights the PT.DateRange.Group line in bold above...

    Where there is a will there are many ways. Finding one that works for you is the challenge!

  • Try this. I used website link below to figure out how to do it


    http://www.globaliconnect.com/excel/...=79&Itemid=475


  • Hi,


    I am getting error:13 Type Mismatch on the StartDate declaration...

    Code
    StartDate = CLng(Range("M1"))

    Where there is a will there are many ways. Finding one that works for you is the challenge!

  • Nevermind,


    My mistake.


    Thanks very much. It worked.

    Where there is a will there are many ways. Finding one that works for you is the challenge!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!