VBA Code to Refresh Pivot If One of Two Cell Values Change

trypsin25

New Member
Joined
Jan 7, 2016
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hello! I am attempting to update code to refresh a pivot table if one of two cells values change. I have tried (unsuccessfully) to write an OR statement in the below. I would like to add that if the value changes in cell E6 or C32 the pivot will refresh. Any help appreciated!!!!


VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = Worksheets("CoExOverview").Range("C32").Address Then
        ActiveSheet.Unprotect Password:="XXXXXX"
        PivotTables("Summary").RefreshTable
        ActiveSheet.Protect Password:="XXXXXX"
        End If
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I assume that the above code is inserted into the Class Module of worksheet CoExOverview; if it's true then you should use, for example
VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$C$32" Or Target.Address = "$E$6" Then
        ActiveSheet.Unprotect Password:="XXXXXX"
        PivotTables("Summary").RefreshTable
        ActiveSheet.Protect Password:="XXXXXX"
        End If
End Sub
Bye
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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