+ Reply to Thread
Results 1 to 3 of 3

Pivot Table programming problem

  1. #1
    DoctorG
    Guest

    Pivot Table programming problem

    I have set up a Pivot with a page field (ProjectCode) so as to total 5
    different fields for a given Project. I then use a Module Level Public
    Function to change this
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Project").CurrentPage =
    <the function parameter> and return the 5 values to the program that called
    the Function.

    If the parameter value exists in the Pivot field values my code works fine.
    If it does not exist in the list though I get an error message at runtime. Is
    there a way to get around this situation? How can I test if the parameter
    exists in the list of the Pivot field values?

  2. #2
    Tom Ogilvy
    Guest

    RE: Pivot Table programming problem

    Dim pvt as PivotTable
    Dim pitm as PivotItem
    Dim s as String
    s = "abc"
    Set pvt = ActiveSheet.PivotTables("PivotTable1")
    For Each pitm In pvt.PageFields("Project").PivotItems
    If lcase(pitm.Value) = lcase(s) Then
    pvt.PageFields(1).CurrentPage = pitm.Value
    Exit For
    End If
    Next

    I usually try to use the value of the pivot item to actually set the
    pagefield as I have had problems myself trying to set it to the string value
    (eventhough it appears to be a match).


    --
    Regards,
    Tom Ogilvy



    "DoctorG" wrote:

    > I have set up a Pivot with a page field (ProjectCode) so as to total 5
    > different fields for a given Project. I then use a Module Level Public
    > Function to change this
    > ActiveSheet.PivotTables("PivotTable1").PivotFields("Project").CurrentPage =
    > <the function parameter> and return the 5 values to the program that called
    > the Function.
    >
    > If the parameter value exists in the Pivot field values my code works fine.
    > If it does not exist in the list though I get an error message at runtime. Is
    > there a way to get around this situation? How can I test if the parameter
    > exists in the list of the Pivot field values?


  3. #3
    DoctorG
    Guest

    RE: Pivot Table programming problem

    Thanks a lot Tom... A precise and complete reply, as always.

    "Tom Ogilvy" wrote:

    > Dim pvt as PivotTable
    > Dim pitm as PivotItem
    > Dim s as String
    > s = "abc"
    > Set pvt = ActiveSheet.PivotTables("PivotTable1")
    > For Each pitm In pvt.PageFields("Project").PivotItems
    > If lcase(pitm.Value) = lcase(s) Then
    > pvt.PageFields(1).CurrentPage = pitm.Value
    > Exit For
    > End If
    > Next
    >
    > I usually try to use the value of the pivot item to actually set the
    > pagefield as I have had problems myself trying to set it to the string value
    > (eventhough it appears to be a match).
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "DoctorG" wrote:
    >
    > > I have set up a Pivot with a page field (ProjectCode) so as to total 5
    > > different fields for a given Project. I then use a Module Level Public
    > > Function to change this
    > > ActiveSheet.PivotTables("PivotTable1").PivotFields("Project").CurrentPage =
    > > <the function parameter> and return the 5 values to the program that called
    > > the Function.
    > >
    > > If the parameter value exists in the Pivot field values my code works fine.
    > > If it does not exist in the list though I get an error message at runtime. Is
    > > there a way to get around this situation? How can I test if the parameter
    > > exists in the list of the Pivot field values?


+ 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