m_wachsman
New Member
- Joined
- Feb 14, 2005
- Messages
- 4
I have the following dilemma:
I have a dynamic range called Pivot_Prop_IDs, which contains numbers.
There are two pivot tables contained in the sheets called PivotGTO and PivotSTR. One of the Pivot fields, called PROP_ID, has some or all of the numbers in the dynamic range.
I'm trying to write a macro so that the pivot table will automatically select the numbers contained in the dynamic range.
So far, what I have is:
Private Sub CommandButton2_Click()
Dim i As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each i In Worksheets("PivotGTO").Range("Pivot_Prop_IDs").Cells
Sheets("PivotGTO").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PROP_ID")
.PivotItems(i.Value).Visible = True
End With
Next
For Each i In Worksheets("Weekly Select Options").Range("Pivot_Prop_IDs").Cells
Sheets("PivotSTR").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PROP_ID")
.PivotItems(i.Value).Visible = True
End With
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
the problem with it is that when the macro runs, Excel seems to select just a few of the numbers in the range, with no rhyme nor reason (at least not to me), but it will consistently select the same numbers even if I shut down Excel and try and restart it.
Any thoughts?
Thanks!
I have a dynamic range called Pivot_Prop_IDs, which contains numbers.
There are two pivot tables contained in the sheets called PivotGTO and PivotSTR. One of the Pivot fields, called PROP_ID, has some or all of the numbers in the dynamic range.
I'm trying to write a macro so that the pivot table will automatically select the numbers contained in the dynamic range.
So far, what I have is:
Private Sub CommandButton2_Click()
Dim i As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
For Each i In Worksheets("PivotGTO").Range("Pivot_Prop_IDs").Cells
Sheets("PivotGTO").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PROP_ID")
.PivotItems(i.Value).Visible = True
End With
Next
For Each i In Worksheets("Weekly Select Options").Range("Pivot_Prop_IDs").Cells
Sheets("PivotSTR").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PROP_ID")
.PivotItems(i.Value).Visible = True
End With
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
the problem with it is that when the macro runs, Excel seems to select just a few of the numbers in the range, with no rhyme nor reason (at least not to me), but it will consistently select the same numbers even if I shut down Excel and try and restart it.
Any thoughts?
Thanks!