Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching a pivot table

Status
Not open for further replies.

mosmas

Technical User
May 22, 2003
61
0
0
US
Hello:

Here is my problem: I have a pivot table that I want to be able to search for a specific value. The problem is my code takes a long time. Is there any way this can be coded so that it run faster. Here is the code that I have:

Sub UniqueItem()

'This routine, uniqueItem, selects the name supplied by the user and display it in the PivotTable

'y is the name that we want to display in the pivot table.
Y = InputBox("Please enter the name you would like to filter")

ActiveSheet.PivotTables("PivotTable7").ManualUpdate = True
On Error Resume Next
For Each X In ActiveSheet.PivotTables("PivotTable7").PivotFields("Rep").PivotItems
X.Visible = False

'x.name is our items collection

'If our collection item is equal to y and "No Rep Info",

'then we want to dispaly them in the pivottable

If X.Name = "No Rep Info" Then X.Visible = True

If X.Name = Y Then X.Visible = True

'This is just to show what item the code is on during the loop.

MsgBox X.Name

Next X

End Sub


thanks in advance
 
Looping through pivottable items does take quite some time - this may speed it up a bit though:
Application.screenupdating = false
For Each X In ActiveSheet.PivotTables("PivotTable7").PivotFields("Rep").PivotItems

If X.Name = "No Rep Info" or X.Name = Y then
X.Visible = True
else
X.visible = false
'This is just to show what item the code is on during the loop.

MsgBox X.Name
Next X


Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top