Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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").AddDataFiel d 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default PivotItem positioning...

Try the recordcount property of the pivot Item.

--
Regards,
Tom Ogilvy


"Jesterhoz" wrote in message
...
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").AddDataFiel d

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a PivotItem ? sharprog Excel Programming 2 July 16th 04 04:39 PM
how to set pivotitem.visible property to true kanan Excel Programming 0 February 25th 04 08:06 PM
How can I set PivotItem.Visible property to True? yumi Excel Programming 2 February 19th 04 11:51 AM
Selecting a PivotItem in code Robert E. Peterson Excel Programming 1 February 4th 04 06:30 PM
Pivotitem count Jesse[_4_] Excel Programming 3 December 28th 03 09:19 PM


All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"