+ Reply to Thread
Results 1 to 5 of 5

Problem with VBA button to refresh worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    07-21-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Problem with VBA button to refresh worksheets

    Hi everyone

    I've created a button (with a VBA script behind it) to update all worksheets in my spreadsheet.

    The problems I'm having are as follows:

    1. Even though I'm asking the script to take me back to the "DONUT VIEW" sheet it isn't. It does briefly but then seems to run through the entire script again and lands me on another worksheet within the spreadsheet.
    2. The script doesn't work at all if I subsequently hide the worksheets. What would I need to do in order to resolve this?

    Thank you for helping with this!

    My script is shown below.

    Best wishes
    Jon

    Sub data_update()
    '
    ' data_update Macro
    '
    '
    Sheets("DATA - Unapproved Income").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    Sheets("DATA - School1").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    ActiveWindow.ScrollWorkbookTabs Sheets:=1
    Sheets("DATA - School2").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    Sheets("DATA - School3").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    Sheets("DATA - School4").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    ActiveWindow.ScrollWorkbookTabs Sheets:=1
    Sheets("PIVOTS").Select
    Range("A6").Select
    ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    Range("A25").Select
    ActiveSheet.PivotTables("PivotTable5").PivotCache.Refresh
    Range("D16").Select
    ActiveSheet.PivotTables("PivotTable4").PivotCache.Refresh
    Range("G2").Select
    ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
    Range("G10").Select
    ActiveSheet.PivotTables("PivotTable7").PivotCache.Refresh
    Range("G20").Select
    ActiveSheet.PivotTables("PivotTable8").PivotCache.Refresh
    Range("G28").Select
    ActiveSheet.PivotTables("PivotTable9").PivotCache.Refresh
    Range("G36").Select
    ActiveSheet.PivotTables("PivotTable10").PivotCache.Refresh
    Range("G44").Select
    ActiveSheet.PivotTables("PivotTable11").PivotCache.Refresh
    Sheets("DONUT VIEW").Select
    End Sub

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,033

    Re: Problem with VBA button to refresh worksheets

    Have you tried just using?

    ActiveWorkbook.RefreshAll
    Sheets("DONUT VIEW").Select
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-21-2018
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Problem with VBA button to refresh worksheets

    Hi Bernie

    Yes, I've tried that too and it still takes me back to a sheet other than the "DONUT VIEW" one.

    Also, would your solution update Pivot tables too (as well as worksheets connected to the database)?

    Best wishes
    Jon

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,033

    Re: Problem with VBA button to refresh worksheets

    Refershall refreshes all external data ranges and PivotTable reports in the workbook object that it is applied to.

    As to not being able to show "Donut view" - Do you have other event code that is changing the active sheet?

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,163

    Re: Problem with VBA button to refresh worksheets

    Our forum rules require you to disclose cross-posts. I will do this for you this once: https://www.mrexcel.com/forum/excel-...orksheets.html

    In future you will be expected to do this yourself. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. RAND Refresh button
    By smudgepost in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2014, 04:01 AM
  2. Refresh spreadsheet via button
    By puuts in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2014, 12:11 PM
  3. Save & Refresh Button
    By Drus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2011, 02:54 PM
  4. Refresh Subtotal's Button
    By Lidos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2007, 04:31 PM
  5. Update/refresh button
    By synchro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2007, 08:21 AM
  6. [SOLVED] Refresh Button
    By Iguss in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-17-2005, 04:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1