+ Reply to Thread
Results 1 to 12 of 12

Clear Pivot Table using VBA

  1. #1
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Clear Pivot Table using VBA

    Hi,

    I have a Pivot table in my excel

    I have a code to clear contents of the Active sheet if MsgBoxClick = "Yes". Along with clearing the contents of the Active sheet, I need Pivot table to be cleared which is in a different sheet.

    Sheet4(PivotTable)

    If MsgBoxClick = vbYes Then rgClear.ClearContents

    I used below, but didn't work.

    If MsgBoxClick = vbYes Then rgClear.ClearContents
    If MsgBoxClick = vbYes Then Sheet4.PivotTables.ClearTable()

    Can anyone please suggest me the way of deleting pivot table.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    04-07-2019
    Location
    Turkey-Ankara-Çubuk
    MS-Off Ver
    Office 2010
    Posts
    71

    Re: Clear Pivot Table using VBA

    Maby,
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Clear Pivot Table using VBA

    Hello,

    I tried below, but did not work. May be I am missing something.


    If MsgBoxClick = vbYes Then rgClear.ClearContents
    If MsgBoxClick = vbYes Then Sheets("sheet4").PivotTables("PivotTable1").TableRange2.Clear

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clear Pivot Table using VBA

    Hello everyone.

    It's not clear to me if you want to delete the pivot table entirely or temporarily delete its data.
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  5. #5
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Clear Pivot Table using VBA

    Hello,

    I am trying to delete the Pivot table.

    I have code to create pivot table, but it remains the same even when the data set changes.

    so, I am looking for an option to delete the pivot table before I change the data.

    Thanks in advance.

  6. #6
    Registered User
    Join Date
    04-07-2019
    Location
    Turkey-Ankara-Çubuk
    MS-Off Ver
    Office 2010
    Posts
    71

    Re: Clear Pivot Table using VBA

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clear Pivot Table using VBA

    Quote Originally Posted by beyond Excel View Post
    Hello everyone.

    It's not clear to me if you want to delete the pivot table entirely or temporarily delete its data.
    Hello. Try with:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Clear Pivot Table using VBA

    Hello,

    Sorry for the delayed reply.

    When I try the above code, I get "Unable to get the Pivot Tables property of the Worksheet class" error.
    Also, to mention, the below statements work on 2 different sheets. Clear contents works on one sheet and Pivot table is in a different sheet that needs to get cleared when the message is yes. The first statement works but the second does not.


    If MsgBoxClick = vbYes Then rgClear.ClearContents
    If MsgBoxClick = vbYes Then ActiveSheet.PivotTables(1).TableRange2.Delete xlShiftUp

  9. #9
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clear Pivot Table using VBA

    Quote Originally Posted by BMD4 View Post
    The first statement works but the second does not.

    If MsgBoxClick = vbYes Then rgClear.ClearContents
    If MsgBoxClick = vbYes Then ActiveSheet.PivotTables(1).TableRange2.Delete xlShiftUp
    One question: What do you imagine ActiveSheet means?...

  10. #10
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Clear Pivot Table using VBA

    AciveSheet is the sheet on which code needs to be executed.

  11. #11
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Clear Pivot Table using VBA

    Quote Originally Posted by BMD4 View Post
    AciveSheet is the sheet on which code needs to be executed.
    Nooo... Not even close!

  12. #12
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    231

    Re: Clear Pivot Table using VBA

    Thank you. I got it to work now.

+ 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. Pivot table Cache clear
    By magnus101 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 10-25-2024, 02:06 AM
  2. [SOLVED] clear pivot table fields
    By stephme55 in forum Excel General
    Replies: 6
    Last Post: 01-22-2016, 08:57 PM
  3. [SOLVED] Clear Cells Except Pivot Table
    By goss in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2015, 05:53 PM
  4. Pivot table - clear filters
    By nativetex in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-31-2014, 09:49 PM
  5. Excel 2007 : How to Clear Pivot Table Filter?
    By dmweinst in forum Excel General
    Replies: 2
    Last Post: 10-01-2009, 01:31 PM
  6. How to clear the Pivot Table in VBA?
    By lazyme in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-04-2007, 04:39 PM
  7. Pivot table Clear Old Items
    By JonSparkes in forum Excel General
    Replies: 2
    Last Post: 03-05-2007, 07:08 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