Excel VBA Pivot Cache Type Mismatch Run-Time Error '13'

前端 未结 1 662
北恋
北恋 2020-12-22 03:25

Thanks for any input on this. I\'m trying to make a simple pivot table that is taking data from sheet \"5 Month Trending May 15\" and putting it onto my Pivot Table sheet ca

相关标签:
1条回答
  • 2020-12-22 03:54

    The documentation for PivotCaches.Create indicates

    The SourceData argument is required if SourceType isn't xlExternal. It can be a Range object (when SourceType is either xlConsolidation or xlDatabase) or an Excel Workbook Connection object (when SourceType is xlExternal).

    Despite this, the macro recorder will always create a String here for the SourceData. (It will even create a bad string if the Sheet has a space in the name).

    Given the preference for the macro recorder, I often supply this as a String with the addresses.

    I have been able before to supply a Range here so I am not certain what is specifically going on that prevents the Range usage in this case.

    To use a String, your code would look like:

    Set pvtCache = ActiveWorkbook.PivotCaches.Create(xlDatabase, "'5 Month Trending May 15'!A2:H38")
    
    0 讨论(0)
提交回复
热议问题