View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
MIKE215 MIKE215 is offline
external usenet poster
 
Posts: 32
Default Visible PivotItems matching criteria

Hi Westg,

Check the value of the pivotitem using the LIKE operator. The LIKE operator
is case sensitive. Something like this should work:

Sub test()
Dim pf As PivotField
Dim pi As PivotItem

Set pf = ActiveSheet.PivotTables("PivotTable1").PivotFields ("Ref")

For Each pi In pf.PivotItems
If Not (pi.Value Like "*QM*") Then
pi.Visible = False
End If
Next

Set pf = Nothing
Set pi = Nothing
End Sub

Every item with a QM in the name should be visible and everything else
should be hidden

Regards,
Mike

"westg" wrote:

How can I use -
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Ref")
.PivotItems("QM").Visible = True

What I want to do is show anything that matches QM (i.e. "QM - 1" or "QM - 2")

Any ideas, I can't use a * or LIKE in the code can I?