+ Reply to Thread
Results 1 to 4 of 4

Pivot Table Problems

  1. #1
    Rachel Gonsior
    Guest

    Pivot Table Problems

    I created a workbook (in Excel 97) that has 8 identical sheets in it and
    another sheet with a pivot table to summarize the data on the 8 sheets. I
    added a button to run a macro to refresh the pivot table after the data was
    entered on the 8 sheets. I sent the file to several people to be completed
    monthly. The file needs to be saved with a new name each month to identify
    the report period. The users have various versions of Excel. When I opened
    the returned files, some were OK but for some, Excel reported that the pivot
    table was invalid and had been discarded. I recreated the pivot tables in
    Excel 2003 but still encounter the same problem. The problem doesn't seem
    to be related to the Excel version, however, because I'm having the same
    problem with files used only on machines with Excel 2003. I'm suspicious
    that it might be related to the changing file names and/or paths. I've had
    to recreate the pivot tables in these files repeatedly so I decided to try
    to automate the process. I recorded a macro while creating the pivot table.
    But I'm having 2 problems.



    When I look at the recorded code, it has the file name in it, as follows:

    CreatePivotTable TableDestination:="'[DAV 02-28-05.xls]Recap'!R3C1",
    _

    TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10



    Is there any way to change the code so it doesn't have to be manually edited
    to change the file name every time it's run? The users also need to be able
    to refresh the pivot table to see the summary data so I need to make the
    macro work without editing.



    The second problem is that if the existing pivot table IS valid, the macro
    bombs because the pivot table already exists. Ideally my macro would just
    refresh the table if it still exists or recreate the table if does not exist
    but I haven't been able to figure out how to do that.



    I would appreciate any help. And I would like to thank all of you who have
    contributed so much of your time and knowledge to helping others use Excel.
    I have learned so much from reading this newsgroup! Thank you!

    Becky







  2. #2
    Debra Dalgleish
    Guest

    Re: Pivot Table Problems

    You can remove the workbook name from the TableDestination string, and
    the macro should work correctly.

    To test for a pivot table, you could use code similar to the following:
    '=========================
    On Error Resume Next
    Set pt = wksPivot.PivotTables(1)
    On Error GoTo 0

    If pt Is Nothing Then
    ' code to build the pivot table
    Else
    pt.PivotCache.Refresh
    End If
    '====================

    Rachel Gonsior wrote:
    > I created a workbook (in Excel 97) that has 8 identical sheets in it and
    > another sheet with a pivot table to summarize the data on the 8 sheets. I
    > added a button to run a macro to refresh the pivot table after the data was
    > entered on the 8 sheets. I sent the file to several people to be completed
    > monthly. The file needs to be saved with a new name each month to identify
    > the report period. The users have various versions of Excel. When I opened
    > the returned files, some were OK but for some, Excel reported that the pivot
    > table was invalid and had been discarded. I recreated the pivot tables in
    > Excel 2003 but still encounter the same problem. The problem doesn't seem
    > to be related to the Excel version, however, because I'm having the same
    > problem with files used only on machines with Excel 2003. I'm suspicious
    > that it might be related to the changing file names and/or paths. I've had
    > to recreate the pivot tables in these files repeatedly so I decided to try
    > to automate the process. I recorded a macro while creating the pivot table.
    > But I'm having 2 problems.
    >
    >
    >
    > When I look at the recorded code, it has the file name in it, as follows:
    >
    > CreatePivotTable TableDestination:="'[DAV 02-28-05.xls]Recap'!R3C1",
    > _
    >
    > TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    >
    >
    >
    > Is there any way to change the code so it doesn't have to be manually edited
    > to change the file name every time it's run? The users also need to be able
    > to refresh the pivot table to see the summary data so I need to make the
    > macro work without editing.
    >
    >
    >
    > The second problem is that if the existing pivot table IS valid, the macro
    > bombs because the pivot table already exists. Ideally my macro would just
    > refresh the table if it still exists or recreate the table if does not exist
    > but I haven't been able to figure out how to do that.
    >
    >
    >
    > I would appreciate any help. And I would like to thank all of you who have
    > contributed so much of your time and knowledge to helping others use Excel.
    > I have learned so much from reading this newsgroup! Thank you!
    >
    > Becky
    >
    >
    >
    >
    >
    >



    --
    Debra Dalgleish
    Excel FAQ, Tips & Book List
    http://www.contextures.com/tiptech.html


  3. #3
    Rachel Gonsior
    Guest

    Re: Pivot Table Problems

    Thank you, Debra. Your suggestions are just what I needed. I've got it
    working now.



    "Debra Dalgleish" <[email protected]> wrote in message
    news:[email protected]...
    > You can remove the workbook name from the TableDestination string, and the
    > macro should work correctly.
    >
    > To test for a pivot table, you could use code similar to the following:
    > '=========================
    > On Error Resume Next
    > Set pt = wksPivot.PivotTables(1)
    > On Error GoTo 0
    >
    > If pt Is Nothing Then
    > ' code to build the pivot table
    > Else
    > pt.PivotCache.Refresh
    > End If
    > '====================
    >
    > Rachel Gonsior wrote:
    >> I created a workbook (in Excel 97) that has 8 identical sheets in it and
    >> another sheet with a pivot table to summarize the data on the 8 sheets.
    >> I added a button to run a macro to refresh the pivot table after the data
    >> was entered on the 8 sheets. I sent the file to several people to be
    >> completed monthly. The file needs to be saved with a new name each month
    >> to identify the report period. The users have various versions of Excel.
    >> When I opened the returned files, some were OK but for some, Excel
    >> reported that the pivot table was invalid and had been discarded. I
    >> recreated the pivot tables in Excel 2003 but still encounter the same
    >> problem. The problem doesn't seem to be related to the Excel version,
    >> however, because I'm having the same problem with files used only on
    >> machines with Excel 2003. I'm suspicious that it might be related to the
    >> changing file names and/or paths. I've had to recreate the pivot tables
    >> in these files repeatedly so I decided to try to automate the process. I
    >> recorded a macro while creating the pivot table. But I'm having 2
    >> problems.
    >>
    >>
    >>
    >> When I look at the recorded code, it has the file name in it, as
    >> follows:
    >>
    >> CreatePivotTable TableDestination:="'[DAV
    >> 02-28-05.xls]Recap'!R3C1", _
    >>
    >> TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    >>
    >>
    >>
    >> Is there any way to change the code so it doesn't have to be manually
    >> edited to change the file name every time it's run? The users also need
    >> to be able to refresh the pivot table to see the summary data so I need
    >> to make the macro work without editing.
    >>
    >>
    >>
    >> The second problem is that if the existing pivot table IS valid, the
    >> macro bombs because the pivot table already exists. Ideally my macro
    >> would just refresh the table if it still exists or recreate the table if
    >> does not exist but I haven't been able to figure out how to do that.
    >>
    >>
    >>
    >> I would appreciate any help. And I would like to thank all of you who
    >> have contributed so much of your time and knowledge to helping others use
    >> Excel. I have learned so much from reading this newsgroup! Thank you!
    >>
    >> Becky
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >
    > --
    > Debra Dalgleish
    > Excel FAQ, Tips & Book List
    > http://www.contextures.com/tiptech.html
    >




  4. #4
    Debra Dalgleish
    Guest

    Re: Pivot Table Problems

    You're welcome. Thanks for letting me know that it helped.

    Rachel Gonsior wrote:
    > Thank you, Debra. Your suggestions are just what I needed. I've got it
    > working now.
    >
    >
    >
    > "Debra Dalgleish" <[email protected]> wrote in message
    > news:[email protected]...
    >
    >>You can remove the workbook name from the TableDestination string, and the
    >>macro should work correctly.
    >>
    >>To test for a pivot table, you could use code similar to the following:
    >>'=========================
    >>On Error Resume Next
    >>Set pt = wksPivot.PivotTables(1)
    >>On Error GoTo 0
    >>
    >>If pt Is Nothing Then
    >> ' code to build the pivot table
    >>Else
    >> pt.PivotCache.Refresh
    >>End If
    >>'====================
    >>
    >>Rachel Gonsior wrote:
    >>
    >>>I created a workbook (in Excel 97) that has 8 identical sheets in it and
    >>>another sheet with a pivot table to summarize the data on the 8 sheets.
    >>>I added a button to run a macro to refresh the pivot table after the data
    >>>was entered on the 8 sheets. I sent the file to several people to be
    >>>completed monthly. The file needs to be saved with a new name each month
    >>>to identify the report period. The users have various versions of Excel.
    >>>When I opened the returned files, some were OK but for some, Excel
    >>>reported that the pivot table was invalid and had been discarded. I
    >>>recreated the pivot tables in Excel 2003 but still encounter the same
    >>>problem. The problem doesn't seem to be related to the Excel version,
    >>>however, because I'm having the same problem with files used only on
    >>>machines with Excel 2003. I'm suspicious that it might be related to the
    >>>changing file names and/or paths. I've had to recreate the pivot tables
    >>>in these files repeatedly so I decided to try to automate the process. I
    >>>recorded a macro while creating the pivot table. But I'm having 2
    >>>problems.
    >>>
    >>>
    >>>
    >>> When I look at the recorded code, it has the file name in it, as
    >>>follows:
    >>>
    >>> CreatePivotTable TableDestination:="'[DAV
    >>>02-28-05.xls]Recap'!R3C1", _
    >>>
    >>> TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    >>>
    >>>
    >>>
    >>>Is there any way to change the code so it doesn't have to be manually
    >>>edited to change the file name every time it's run? The users also need
    >>>to be able to refresh the pivot table to see the summary data so I need
    >>>to make the macro work without editing.
    >>>
    >>>
    >>>
    >>>The second problem is that if the existing pivot table IS valid, the
    >>>macro bombs because the pivot table already exists. Ideally my macro
    >>>would just refresh the table if it still exists or recreate the table if
    >>>does not exist but I haven't been able to figure out how to do that.
    >>>
    >>>
    >>>
    >>>I would appreciate any help. And I would like to thank all of you who
    >>>have contributed so much of your time and knowledge to helping others use
    >>>Excel. I have learned so much from reading this newsgroup! Thank you!
    >>>
    >>>Becky
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>

    >>
    >>
    >>--
    >>Debra Dalgleish
    >>Excel FAQ, Tips & Book List
    >>http://www.contextures.com/tiptech.html
    >>

    >
    >
    >



    --
    Debra Dalgleish
    Excel FAQ, Tips & Book List
    http://www.contextures.com/tiptech.html


+ 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