+ Reply to Thread
Results 1 to 7 of 7

Object Required Error

Hybrid View

  1. #1
    Registered User
    Join Date
    12-23-2011
    Location
    pomona, ca
    MS-Off Ver
    Excel 2010
    Posts
    36

    Object Required Error

    Hi All,

    I have run into an error in creating a pivot table. The error says object required, but I believe that I already have an object there. I'm sure this will be easy for the wiz' out there! The error occurs after the pivot table is created and where I start the "with PT." Thanks!

    samplewb.xlsm

    Sub Pivot()
    
    Dim PTCache As PivotCache
    Dim PT As PivotTable
    
    'Create Cache
    Set PTCache = ActiveWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=Sheets("Breakdown").Range("a1").CurrentRegion)
        
    'Add a New WS to the WB
    Worksheets.Add.Name = "Pivot"
    
    'Create Pivot Table
    Set PT = ActiveSheet.PivotTables.Add( _
        PivotCache:=PTCache, _
        tabledestination:=Range("a1"))
        
    'Specify the fields
    With PT
        .PivotFields("Notification Reference Date").Orientation.xlColumnField
        .PivotFields("Equipment Name").Orientation.xlRowField
        .PivotFields("District Text").Orientation.xlRowField
        .PivotFields("Equipment Name").Orientation.xlDataField
        'no field captions
        .DisplayFieldCaptions = False
    End With
    
    Range("B2").Select
        Selection.Group Start:=True, End:=True, Periods:=Array(False, False, False, _
            False, True, False, False)
        
        
    End Sub
    Last edited by tlinton; 06-12-2012 at 10:44 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,434

    Re: Object Required Error

    You don't say where the error occurs.

    And it would be good to have a sample of the workbook which exhibits the problem.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-23-2011
    Location
    pomona, ca
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Object Required Error

    Okay, I have added the file and where it errors. Thanks for your help and sorry I forgot some useful info!

  4. #4
    Registered User
    Join Date
    12-23-2011
    Location
    pomona, ca
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Object Required Error

    Whoops!!! You are going to need to run the Remove breakdown macro first!! In order for the macro i am having issues with to work properly

  5. #5
    Registered User
    Join Date
    12-23-2011
    Location
    pomona, ca
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Object Required Error

    Okay, now you can run the Pivot code with out running the breakdown code. Sorry for the many posts. Dont know how to delete the old ones. Thanks

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Object Required Error

    should be
       .PivotFields("Notification Reference Date").Orientation = xlColumnField
        .PivotFields("Equipment Name").Orientation = xlRowField
        .PivotFields("District Text").Orientation = xlRowField
        .PivotFields("Equipment Name").Orientation = xlDataField
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Registered User
    Join Date
    12-23-2011
    Location
    pomona, ca
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Object Required Error

    Jeepers!! I can't believe I didn't see that!! Thanks a lot Joseph!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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