Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Hal Hal is offline
external usenet poster
 
Posts: 36
Default For Each Next, Case Select

I would like to get the code below to work by looking for each PivotItem and
if it exists, set the Visible property to False. I've tried to nest a Case
Select within a For Each loop but I can not get this to work for me.

Any and all help is greatly appreciated.



With ActiveSheet.PivotTables("PivotTable1").PivotFields ("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("ENGINE STATUS")
.PivotItems("LD-RV").Visible = False
.PivotItems("TS367-092").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-EN").Visible = False
.PivotItems("TS-FA").Visible = False
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default For Each Next, Case Select

I haven't tested the code below but I think both methods should work

Method 1:

for TableCount = 1 to 10
With ActiveSheet.PivotTables("PivotTable" &
TableCount1).PivotFields("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
Next TableCount

Method 2:

for each PT in ActiveSheet.PivotTables
With PT.PivotFields("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
next PT
"Hal" wrote:

I would like to get the code below to work by looking for each PivotItem and
if it exists, set the Visible property to False. I've tried to nest a Case
Select within a For Each loop but I can not get this to work for me.

Any and all help is greatly appreciated.



With ActiveSheet.PivotTables("PivotTable1").PivotFields ("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("ENGINE STATUS")
.PivotItems("LD-RV").Visible = False
.PivotItems("TS367-092").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-EN").Visible = False
.PivotItems("TS-FA").Visible = False
End With

  #3   Report Post  
Posted to microsoft.public.excel.programming
Hal Hal is offline
external usenet poster
 
Posts: 36
Default For Each Next, Case Select

Thanks for the reply Joel. I'll give these a try and post back on the
results. The problem I faced with just using the WITH option is that if I
added a potential field that doesn't exist in the data set I'm working with,
it caused the code to bomb. In other words, the active PivotItems change form
day to day on the data I collect.

Kind Regards,

"Joel" wrote:

I haven't tested the code below but I think both methods should work

Method 1:

for TableCount = 1 to 10
With ActiveSheet.PivotTables("PivotTable" &
TableCount1).PivotFields("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
Next TableCount

Method 2:

for each PT in ActiveSheet.PivotTables
With PT.PivotFields("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
next PT
"Hal" wrote:

I would like to get the code below to work by looking for each PivotItem and
if it exists, set the Visible property to False. I've tried to nest a Case
Select within a For Each loop but I can not get this to work for me.

Any and all help is greatly appreciated.



With ActiveSheet.PivotTables("PivotTable1").PivotFields ("ENGINE STATUS")
.PivotItems("IN-SP").Visible = False
.PivotItems("SA-FA").Visible = False
.PivotItems("SD-WF").Visible = False
.PivotItems("SD-WR").Visible = False
.PivotItems("TS367-094").Visible = False
.PivotItems("TS367-096").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-FA").Visible = False
.PivotItems("TS-SA").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("ENGINE STATUS")
.PivotItems("LD-RV").Visible = False
.PivotItems("TS367-092").Visible = False
.PivotItems("TS-DP").Visible = False
.PivotItems("TS-EN").Visible = False
.PivotItems("TS-FA").Visible = False
End With

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
Select case Hein Excel Discussion (Misc queries) 2 October 22nd 08 07:06 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Select Case achidsey Excel Programming 4 September 18th 05 05:24 PM


All times are GMT +1. The time now is 08:34 PM.

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

About Us

"It's about Microsoft Excel"