简体   繁体   中英

Excel VBA running a macro

I'd like to run a macro which will update to extracts by selecting today()-1 in slicers with Macro. But I can't get it work.

I've tried to get date from cell value, and tried with Date and Now functions too. None of them worked. Anyone with any idea?

I get:

  • Run-time error '1004' String can't be converted to type date. or
  • Run-time error '1004' The item couldn't be found in OLAP Cube.
Sub Update_date()
'
' Update_date Macro
'
    Dim MyDate As Range
    Set MyDate = ThisWorkbook.Worksheets("Slicers").Range("D2")
'
    ActiveWorkbook.SlicerCaches("Slicer_Ship_Date").VisibleSlicerItemsList = Array _
        ( _
        "[Sales Orders].[Ship Date].MyDate")
    ActiveWorkbook.SlicerCaches("Slicer_Ship_Date1").VisibleSlicerItemsList = Array _
        ( _
        "[Sales Orders].[Ship Date].MyDate") 
End Sub
Sub Update_date()
'
' Update_date Macro
'
'
' Update_date Macro
'
    Dim MyDate As Range
    Dim MyDate2
    
    Set MyDate = ThisWorkbook.Worksheets("Slicers").Range("D2")
    MyDate2 = Format(MyDate, "yyyy-MM-ddTHH:mm:ss")
'
    ActiveWorkbook.SlicerCaches("Slicer_Ship_Date").VisibleSlicerItemsList = Array _
        ( _
        "[Sales Orders].[Ship Date].&[" & MyDate2 & "]")
    ActiveWorkbook.SlicerCaches("Slicer_Ship_Date1").VisibleSlicerItemsList = Array _
        ( _
        "[Sales Orders].[Ship Date].&[" & MyDate2 & "]")

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM