'Excel VBA Timeline slicerChache doesnt work with data from power query

I have a code where Pivot timeline date is changing based on the date.

Previously I had an sheet with data, but recently change the data source to from power query.

My error is that Timeline slicer doesn't work anymore.

Does anyone know why this error can occure?

ERROR : Run-time error '5' :

Invalid procedure call or argument.


Sub Datos_nustatymas()

    Dim wb As Workbook, ws As Worksheet
    Dim Lastrow As Long, i As Long, r As Long
    Dim dt As Date, dtLast As Date, newdays As Long
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Set wb = ThisWorkbook

    wb.RefreshAll ' Refresh Pivot '
    
    
    Set ws = wb.Sheets("Report")
    With ws
    
        ' find end of existing data in B
        Lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
        
        ' calc number of days to yesterday
        dtLast = .Range("A" & Lastrow).Value2
        newdays = Date - 1 - dtLast
        
        If newdays < 1 Then
            MsgBox "Report is up to date", vbExclamation
            Exit Sub
        Else
            ' extend column A to yesterday
            With .Range("A" & Lastrow + 1).Resize(newdays)
                .Formula = "=R[-1]C+1"
                .Value = .Value
            End With
        End If
        
        'update column B
        For i = 1 To newdays
            r = Lastrow + i
            dt = .Cells(r, "A")
            
             ' this code selects a timeline date
            ActiveWorkbook.SlicerCaches("NativeTimeline_VALUE_DATE").TimelineState. _
                SetFilterDateRange dt, dt
                
            ' Copy/Paste details from Pivot to celected cells'
            .Range("O4:Z4").Copy
            .Cells(r, "B").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        
        Next
    End With
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True


    MsgBox newdays & " days added", vbInformation
    
        
End Sub```




Solution 1:[1]

Fixed. Just changed "NativeTimeline_VALUE_DATE" to "Timeline_VALUE_DATE" and it worked.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mindaugas Vilimas