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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,524
Messages
6,114,117
Members
448,549
Latest member
brianhfield

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