Macro for refresh of pivot table and return to the active sheet.

Usman Malik

New Member
Joined
Mar 19, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am working on an excel workbook having multiple sheets. I have placed a macro for the refresh of the pivot table. But after refreshing it return to the sheet i have select at the time of recording the macro. Kindly help me, as i want to return to the active sheet I am working on.

Refersh Macro
'

'
Sheets("Done").Select
Range("B8").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Range("A33").Select
Sheets("Pending").Select
Range("B9").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Sheets("19").Select
End Sub

This return me to sheet 19 always
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,091
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub RefreshMacro()
    Dim ws As Worksheet
    Set ws = ActiveSheet
    Sheets("Done").Select
    Range("B8").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Range("A33").Select
    Sheets("Pending").Select
    Range("B9").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    ws.Select
End Sub
 

Usman Malik

New Member
Joined
Mar 19, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
VBA Code:
Sub RefreshMacro()
    Dim ws As Worksheet
    Set ws = ActiveSheet
    Sheets("Done").Select
    Range("B8").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Range("A33").Select
    Sheets("Pending").Select
    Range("B9").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    ws.Select
End Sub
Thanks its working
 

Watch MrExcel Video

Forum statistics

Threads
1,129,991
Messages
5,639,415
Members
417,088
Latest member
jonstr101

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
Top