BigBadBarry
New Member
- Joined
- Oct 23, 2013
- Messages
- 5
Hi all (second thread this morning!),
I have managed to use some VB code (in Sheet2) to update a Pivot Table filter based on a value in my sheet (cell F1), pieced together from this forum.
What I can't do though is get F1 to reference another sheet (i.e. ='Sheet1'!C2) and update automatically. I have the VB in the worksheet with the Pivot table on, and obviously it doesn't run when I change cell C2 in Sheet 1.
I've tried to solve it myself using various sources and code in Sheet 1 or the module as well, but I am stuck. Any help would be greatly appreciated! The code in Sheet 2 is as follows:
I have managed to use some VB code (in Sheet2) to update a Pivot Table filter based on a value in my sheet (cell F1), pieced together from this forum.
What I can't do though is get F1 to reference another sheet (i.e. ='Sheet1'!C2) and update automatically. I have the VB in the worksheet with the Pivot table on, and obviously it doesn't run when I change cell C2 in Sheet 1.
I've tried to solve it myself using various sources and code in Sheet 1 or the module as well, but I am stuck. Any help would be greatly appreciated! The code in Sheet 2 is as follows:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String
strField = "Project"
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Address = Worksheets("Sheet10").Range("F1").Address Then
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
With pt.PageFields(strField)
For Each pi In .PivotItems
If pi.Value = Target.Value Then
.CurrentPage = Target.Value
Exit For
Else
.CurrentPage = "(All)"
End If
Next pi
End With
Next pt
Next ws
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub