Excel Slicer and TimeLine

Dear Friends,

I have a timeline in excel.I need to set range. Any one is having any idea.


1 Like

Have you tried using VBA?

1 Like

Thank you @KarthikByggari. Happy New Year . No . I didn’t try the VBA Karthik . But I will take a look in VBA. and you ping you here.

Thank you

1 Like

Hi @balupad14

Check this

Private Sub Workbook_SheetPivotTableUpdate(ByVal Sh As Object, ByVal Target As PivotTable)

'   Description:Update Timeline Slicers from Master Slicer
'   Inputs:     Sh          PivotTable's worksheet
'               Target      PivotTable being changed/updated
'   Outputs:    *None
'   Requisites: *None
'   Example:    *None - This is an event handler found in ThisWorkbook module

'     Date   Ini Modification
'   10/19/16 CWH Initial Development

'   Declarations
    Const cRoutine      As String = "Workbook_SheetPivotTableUpdate"
    Dim oSlicer         As SlicerCache      'Current Slicer
    Const cSlicer       As Long = 1         'Master Slicer
    Dim dStartDate      As Date             'Start Date
    Dim dEndDate        As Date             'End Date
    Dim bCleared        As Boolean          'Filter Cleared Flag
    Dim bEvents         As Boolean          'Events Enabled Flag

'   Error Handling Initialization
    On Error GoTo ErrHandler

'   Prevent cascading events
    bEvents = Application.EnableEvents
    Application.EnableEvents = False

'   Get Master Slicer's dates
    Set oSlicer = ThisWorkbook.SlicerCaches(cSlicer)
    bCleared = oSlicer.FilterCleared
    If Not bCleared Then
        With oSlicer.TimelineState
            dStartDate = .FilterValue1
            dEndDate = .FilterValue2
        End With
    End If

'   Set All other Timeline Slicer Dates
    For Each oSlicer In ThisWorkbook.SlicerCaches
        If oSlicer.SlicerCacheType = xlTimeline And _
           oSlicer.Index <> cSlicer Then
            If bCleared Then _
                oSlicer.ClearAllFilters Else _
                    oSlicer.TimelineState.SetFilterDateRange _
                        StartDate:=dStartDate, EndDate:=dEndDate
        End If

    Select Case Err.Number
        Case Is = 0:                            'Do nothing
        Case Is = 9:                            'Do Nothing Master Slicer Missing
        Case Else:
            Select Case MsgBox(Prompt:=Err.Description, _
                               Buttons:=vbAbortRetryIgnore, _
                               Title:=cRoutine, _
                               HelpFile:=Err.HelpFile, _
                Case Is = vbAbort:  Stop: Resume    'Debug mode - Trace
                Case Is = vbRetry:  Resume          'Try again
                Case Is = vbIgnore:                 'End routine
            End Select
    End Select
'   Clean up: Resume responding to events
    Application.EnableEvents = bEvents

End Sub

ashwin S

Hi @AshwinS2,

Great , Happy New Year . definitely I will take a look and ping here.

Thank you

Happy new year @balupad14 :slight_smile:

1 Like