Another simple ( I hope) question

Angelyne

New Member
Joined
May 11, 2020
Messages
7
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You have been so helpful to me already. I have another question and this is going to make my spreadsheet a zillion time better

This is my code. I took it from a helpful website. When I enter the pf.CurrentPage value directly into the code, (as below) this works perfectly. But what I really want is to set pf.CurrentPage to the value of a formula in C3. I tried doing pf.CurrentPage = "C3" but that gave me an error. That formula doesn't seem to work for some reason. Any thoughts?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'PURPOSE: Filter on a single item with the Report Filter field
'SOURCE: www.TheSpreadsheetGuru.com

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables("PivotTable2").PivotFields("Cost Centre (Existing)")

'Clear Out Any Previous Filtering
pf.ClearAllFilters

'Filter on cost center
pf.CurrentPage = "3452"


End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Yes it works. It doesn't work when I tried to use pf.CurrentPage.value = "E3" (Where E3 value is 3452)
 
Upvote 0
But I need the formula to use the value in the cell E3, otherwise, it's just hard-coding the filter value in the code, which is useless to me
 
Upvote 0
I had hoped inserting ".value" would have done the trick. Sorry I can't be of further assistance.
 
Upvote 0
Yes!! figured this out. Adding the code in bold made this code works :

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables("PivotTable2").PivotFields("Cost Centre (Existing)")
NewCat = Worksheets("Inventory").Range("C3").Value

'Clear Out Any Previous Filtering
pf.ClearAllFilters

'Filter on cost center
pf.CurrentPage = NewCat
 
Upvote 0
Excellent !!!


It's always better when the solution comes from your brain instead of someone else's >>>>>
 
Upvote 0

Forum statistics

Threads
1,215,568
Messages
6,125,599
Members
449,238
Latest member
wcbyers

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