Worksheet Change Event

one3nine0

Board Regular
Joined
Jul 21, 2014
Messages
127
I have a cell that is a formula based off pivot table. The value will change with slicers that the user can select from.

How do I have the workbook refresh every time the value of the cell changes?

What I have so far is:

In Sheet1 object:
Private Sub Worksheet_Calculate()
If Range("E7").Value <> PrevVal Then
ActiveWorkbook.RefreshAll
End If
End Sub

But how do I make PrevVal equal the previous value of the cell before the change? or how do I make it so that the workbook will refresh once E7 changes?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

Use this in the worksheet macro to trigger on on a change in the sheet:
Code:
<code>Private Sub Worksheet_Change(ByVal Target As Range)</code>
Next use this code to only trigger when E7 is changed:
Code:
If Target = Range("E7") Then
    ActiveWorkbook.RefreshAll
End If
 
Upvote 0
Hi,

Use this in the worksheet macro to trigger on on a change in the sheet:
Code:
<code>Private Sub Worksheet_Change(ByVal Target As Range)</code>
Next use this code to only trigger when E7 is changed:
Code:
If Target = Range("E7") Then
    ActiveWorkbook.RefreshAll
End If


Hey Dendro, unfortunately, because E7 contains a formula, this doesn't work. The formula doesn't change which in turn doesn't trigger the event. Only the value of the formula result changes, and I am not sure how to trigger the event for that instance.
 
Upvote 0
For what its worth, there must be a cell thats changed to make the pivot table change, so perhaps the answer is to trigger the event when that occurs and then force an update to the pivottable as part of the macro.

Regards
 
Upvote 0
For what its worth, there must be a cell thats changed to make the pivot table change, so perhaps the answer is to trigger the event when that occurs and then force an update to the pivottable as part of the macro.

Regards

So I am using powerpivot and slicers to change the tables, so unless I can target a portion of a pivot table or when the slicer is changed, then I dont think that would work.
 
Upvote 0
Oh, sorry, I dont have any experience with either powerpivot or slicers. Though I would have anticipated some way of trapping the action of a slicer - perhaps if you record a macro as you adjust the slicer you'll get some insight that will be useful.

Good luck.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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