• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Combine 2 VBA Code

Dokat

Member
Hi,

How can i combine below 2 codes in VBA?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim xPTable As PivotTable
Dim xPFile As PivotField
Dim xStr As String


On Error Resume Next
If Intersect(Target, Target.Worksheet.Range("B4")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("Source Data").PivotTables("PivotTable1")
Set xPFile = xPTable.PivotFields("Geography")
xStr = Target.Value
With xPFile
.ClearAllFilters
.PivotFilters.Add2 xlCaptionEquals, Value1:=xStr
End With
Application.ScreenUpdating = True


On Error Resume Next
If Intersect(Target, Target.Worksheet.Range("A3")) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xPTable = Worksheets("Source Data").PivotTables("PivotTable1")
Set xPFile = xPTable.PivotFields("% Dollar Sales by Merch Any Price Reduction")
xStr = Target.Value
With xPFile
.ClearAllFilters
.PivotFilters.Add2 xlCaptionEquals, Value1:=xStr
End With
 
Looks like you have already completed the combination. Just end it wit END SUB.

What happens then ?
 
It only runs the first code and not the second. I am trying change 2 filters in a pivot table based on a cell value in a different sheet. It only works partially.

Looks like you have already completed the combination. Just end it wit END SUB.

What happens then ?
 
Back
Top