+ Reply to Thread
Results 1 to 2 of 2

PivotItem positioning...

  1. #1
    Jesterhoz
    Guest

    PivotItem positioning...

    Hello All,

    I have a macro that runs and creates a pivot table. I included some code
    that says to put PivotItem("January") before PivotItem("February"), for
    instance. However, sometimes, I may run the macro and the data that is being
    used doesn't contain any January items. So, it errors out and tells me that
    it couldn't find a column for January. I want to know if there is a way to
    merely say "If there is a PivotItem("January"), put it in position 1, else
    ignore and look for PivotItem("February"), etc."

    Here is a snippet of the code if it helps:

    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("CURRENT"), "Sum of CURRENT", xlSum
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
    _("March").Position = 3
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
    _("February").Position = 2
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
    _("January").Position = 1

    Any help would be much appreciated.

    Thanks,

    Trevor

  2. #2
    Tom Ogilvy
    Guest

    Re: PivotItem positioning...

    Try the recordcount property of the pivot Item.

    --
    Regards,
    Tom Ogilvy


    "Jesterhoz" <[email protected]> wrote in message
    news:[email protected]...
    > Hello All,
    >
    > I have a macro that runs and creates a pivot table. I included some code
    > that says to put PivotItem("January") before PivotItem("February"), for
    > instance. However, sometimes, I may run the macro and the data that is

    being
    > used doesn't contain any January items. So, it errors out and tells me

    that
    > it couldn't find a column for January. I want to know if there is a way

    to
    > merely say "If there is a PivotItem("January"), put it in position 1, else
    > ignore and look for PivotItem("February"), etc."
    >
    > Here is a snippet of the code if it helps:
    >
    > ActiveSheet.PivotTables("PivotTable1").AddDataField

    ActiveSheet.PivotTables( _
    > "PivotTable1").PivotFields("CURRENT"), "Sum of CURRENT", xlSum
    > ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
    > _("March").Position = 3
    > ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
    > _("February").Position = 2
    > ActiveSheet.PivotTables("PivotTable1").PivotFields("Month").PivotItems
    > _("January").Position = 1
    >
    > Any help would be much appreciated.
    >
    > Thanks,
    >
    > Trevor




+ 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