Copy/Paste into Pivot Filter VBA

ADeYoung

Board Regular
Joined
Jun 28, 2004
Messages
113
I am trying to run a macro on a few items(24) in a large pivot table(6000). How can I run through a list, one at a time and then run another macro?

Here is what I have:

Sheets("Random Demand").Select
Range("O1").Select
ActiveCell.FormulaR1C1 = "D12549.256"
Sheets("Item Lookup").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("ITEM_NUMBER").CurrentPage _
= "D12549.256"
'Run other code here, then loop back and choose the next item on the list

The problem is the ActiveCell.FormulaR1C1 = "D12549.256", the range if cells with the items I need to use is Range("O1:O24"), that is what I want to use since the data will change and needs to be dynamic. any ideas?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi ADeYoung,

You could try the code below.

Code:
Sub Step_Through_PageFilters()
    Dim c As Range
    Dim PT As PivotTable
    Set PT = Sheets("Item Lookup").PivotTables("PivotTable1")

    
    For Each c In Sheets("Random Demand").Range("O1:O24")
        With PT.PivotFields("ITEM_NUMBER")
            .ClearAllFilters
            On Error Resume Next
            .CurrentPage = c.Text
            On Error GoTo 0
            If .CurrentPage.Value = c.Text Then
                

                [COLOR="#008080"]'Run other code here....[/COLOR]
               

                
            Else
                MsgBox c.Text & " pagefield item not found."
            End If
        End With
    Next c
End Sub

It's more efficient to just reference the objects directly as shown in this code instead of using "Select" and "ActiveCell".
 
Upvote 0

Forum statistics

Threads
1,215,165
Messages
6,123,387
Members
449,098
Latest member
ArturS75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top