ActiveSheet Refresh

happyhungarian

Board Regular
Joined
Jul 19, 2011
Messages
218
Hi, I think this is a simple question but I can't figure it out. I'm using this code to refresh a pivot if data on a worksheet is changed but it's refreshing all pivots rather than just the pivots on the active worksheet. Where I'm running into issues is that I dont want to have to specify the name of the sheet in the code. I want to use an ActiveSheet type of logic.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)


ThisWorkbook.RefreshAll



End Sub
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. Windows
Try:

Code:
[COLOR=#333333][FONT=Verdana]Private Sub Worksheet_SelectionChange(ByVal Target As Range)[/FONT][/COLOR]
    Dim td As PivotTable
    For Each td In ActiveSheet.PivotTables
        td.PivotCache.Refresh
    Next
End Sub
 
Last edited:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,001
Messages
5,526,199
Members
409,686
Latest member
Tori83

This Week's Hot Topics

Top