+ Reply to Thread
Results 1 to 4 of 4

Run-time error '1004': Unable to get the PivotTables property of the worksheet class

  1. #1
    Registered User
    Join Date
    05-09-2017
    Location
    Iowa
    MS-Off Ver
    2010
    Posts
    2

    Run-time error '1004': Unable to get the PivotTables property of the worksheet class

    Good Afternoon,

    I'm a newbie to ZBA and researched the error code. I believe the issue is with this line of code: Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&. I understand the first part declares worksheet variable but not sure I follow the rest of it. As far as the next line of code goes the Pivot name is correct: ActiveSheet.PivotTables ("PviotTable1").PivotCache.Refresh ---> Run-time error pops-up on this line. I've pasted part of the Module below since it is fairly long. I appreciate any help or pointers in the right direction.

    Sub filter_distr_report()

    Dim newdist() As String
    Dim LR, LR2, LR3, LR4 As Long
    Dim lastrow2 As Long
    Dim newtest, distnumb, actdate, distnotincluded As String
    Dim bldate As Date
    Dim worksheet_name As String
    Dim filter, filter2, mmyyy, mm, yyyy As String
    Dim Sheet As Worksheet, SheetName$, MyFilePath$, N&

    'refresh report
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh

    'MyFilePath$ = ActiveWorkbook.Path & "\" & _
    'Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4)

    MyFilePath$ = ActiveWorkbook.Path & "\Top Dist PDFs"

    ' ReDim cdRack(0 To 1, 0 To 3) As String

    ' A CD rack for the Beatles
    ' cdRack(0, 0) = "Rubber Soul"


    'to run in backlog/report macro as well as stand alon:
    ' check name of current sheet - if not "New Dist", then it is backlog/report

    worksheet_name = ActiveSheet.name

    Sheets("Top Dist").Activate

    LR = ActiveSheet.Cells(Rows.count, 1).End(xlUp).Row

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Run-time error '1004': Unable to get the PivotTables property of the worksheet class

    The error is telling you that it can't find a pivot table named "PivotTable1" on the active worksheet.

    This may be because the pivot table is named incorrectly (you have two different names in your post - typo?), or it may be that the sheet containing the pivot table is not the active sheet when that line of code is running. It may be better to reference the sheet containing the pivot table directly...
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Run-time error '1004': Unable to get the PivotTables property of the worksheet class

    What Olly said. Also, when dim'ing variables, with lines like 'Dim newtest, distnumb, actdate, distnotincluded As String' newtest, distnumb and actdate are defined as variants, only the distnotincluded is defined as a string.

  4. #4
    Registered User
    Join Date
    05-09-2017
    Location
    Iowa
    MS-Off Ver
    2010
    Posts
    2

    Re: Run-time error '1004': Unable to get the PivotTables property of the worksheet class

    The pivot table name is correct. I went to pivot table options and it shows name as PivotTable1. I wasn't sure if I call out the exact name of worksheet if it would mess up the rest of the Macro.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error 1004: Unable to get the PivotTables propert of the Worksheet class
    By Netzqua in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-13-2016, 02:14 PM
  2. run time error 1004 unable to set the hidden property of the worksheet class
    By curness in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2015, 05:41 PM
  3. run time error 1004 unable to get the oleobjects property of the worksheet class in excel
    By Ardiagarana212 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-09-2014, 06:51 AM
  4. Replies: 1
    Last Post: 12-17-2012, 01:24 PM
  5. Replies: 0
    Last Post: 11-01-2012, 10:44 PM
  6. Run time error 1004 unable to get the vlookup property of the worksheet function class
    By surajitbose in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 06:12 PM
  7. Run-Time error '1004: Unable to get the PivotTables property of the worksheet class
    By magarnagle in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2006, 06:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1