+ Reply to Thread
Results 1 to 13 of 13

Macro suddenly no longer works

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Macro suddenly no longer works

    Hello,

    I inherited a file with macro.

    It had been working for years and suddenly for some reason, it stopped working today

    The "error" that was highlighted was below

    Sheets ("My Sheet Name").select    <-- This is the one that's always being highlighted.
    Range("A1").Select
    Sheets("My Sheet Name").PivotTables("BudgetChanges").RefreshTable
    Note that if I were to move my debug into the next row of the code and run it, the macro will run completely fine.

    However, when it goes to the next line of codes that have the same selection of sheet.

    i.e. Sheets ("Another Sheet Name").select

    It'll stop here again.

    What's the issue and how to resolve it?

    Thank you!

    Note that I've asked my other colleagues to run and they don't have this issue. Only my computer.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,825

    Re: Macro suddenly no longer works

    When it highlights that line, what is the error number and error description that are shown?

    Note that if I were to move my debug into the next row of the code and run it, the macro will run completely fine.
    I'm not following how you can do that. Once you hit an error, if you hit F8 to continue you will always* get the same error and not be able to proceed. And you can't use the debugger to start execution in the middle of a sub.

    ______________________________
    *There are probably very rare exceptions.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,818

    Re: Macro suddenly no longer works

    There shouldn't be a space on that line between Sheets and ("My Sheet Name"). And select would normally have a capital S.

    What error code are you getting? Could any of the sheet names have changed?

    Post ALL the code, ideally in a sample/redacted workbook.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Macro suddenly no longer works

    I tried it again, and this time it's giving me a different error.

    However, the same "Run-time error 1004" code. But this time it's showing on the 'ShowAllData' method, instead of the .select

    To answer your question on the F8, all I did here was that I left click and hold the arrow of the debug that was highlighted and move it to the next line of code and then run it again F5.

    Error Message.png

    Debug.png
    Last edited by dluhut; 08-15-2023 at 05:21 PM.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,818

    Re: Macro suddenly no longer works

    @6SJ: you can drag the highlight down to the next row and continue execution from there.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,825

    Re: Macro suddenly no longer works

    Quote Originally Posted by TMS View Post
    @6SJ: you can drag the highlight down to the next row and continue execution from there.
    Well damn, you learn something new every day. I can't believe I I didn't know that in the number of years I've been using VBA.

  7. #7
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Macro suddenly no longer works

    @TMS I'm sorry that I can't share the workbook neither sample of the code as it'll return error 1st thing if it's not in VPN.

    However, in my 2nd post, I've posted the sample code that gives me the error.

    In my 1st writing, it's giving me the error on the Sheets("Another Sheet Name").Select

    But now it bypass this error and it's giving me the .ShowAll error method instead.

    Seems like the 'On error resume next' didn't work here.

    Yet again, if I were to move the debug row to the next row of code and run the code again, it'll run the code and still give me the same error message on the next line of code that has the '.ActiveSheet.ShowAllData'

    The point that I want to make is this. I've ran this macro for at least 2 years and didn't make any changes to it. It's only happen today that it starts giving me problem

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro suddenly no longer works


    Hello,

    so according to your red writtings it can't be the code - even if IMO badly coded - but something else
    then without the necessary it's just a guessing challenge
    so you have more chance to find out yourself with checking each name, each variable content, …
    Maybe just restarting from a backup.
    Last edited by Marc L; 08-15-2023 at 05:58 PM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,818

    Re: Macro suddenly no longer works

    It worked. Now it doesn't. Something HAS changed. You've not changed the code. Has/have the sheet name(s) changed? If it doesn't like the sheet names and it doesn't like the Tables, is the right workbook open?

    First suggestion. Save all your workbooks, shut down Excel and just start Excel and test the Excel application. Test. If it works, good. If it doesn't, save ALL your work, close ALL your applications, shut down the machine. Start it up again. Just start Excel and test the Excel application.

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,825

    Re: Macro suddenly no longer works

    This isn't causing your problem (probably) but it's generally error-prone to manage sheet operations by selecting/activating a sheet then relying on ActiveSheet to refer to it. It's better to explicitly qualify references, which could be done nicely here using a With statement. Same goes for selecting ranges then referring to Selection.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,818

    Re: Macro suddenly no longer works

    @6SJ: main reason for asking for the code is/was to see that kind of issue.

    Could be as simple as the workbook saved with a different sheet selected than is the norm and the coding expecting to start with one thing and getting another. Again, not here, given the selection, but the prior code may not have done something it was intended to. Maybe we'll never know.

    And thanks for the rep, by the way

  12. #12
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Macro suddenly no longer works

    Thanks all for trying to help!

    No changes to the the code. No changes to sheet name etc.

    It's literally an overnight, what works yesterday didn't work today.

    I thought if it's something to do with software updates, but it's not.

    And like I was saying, initially, the error was something to do with Sheet selection. After restarting my computer and try re-run the macro, instead of Sheet Selection error, it's giving me ShowAllData error.

    Restarted again, and re-run and it's the same ShowAllData error message.

    So really at a loss as to what's the issue here.

    Worst comes to worst, I'll re-write the code on my own, and like @6StringJazzer said, instead of using .Select, I'll be using .Activate perhaps.

    Now just need to know how to refresh the query table

    Need to change Selection.ListObject.QueryTable.Refresh

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,825

    Re: Macro suddenly no longer works

    Using Activate is the same problem.

    Just as an example, instead of this:
    Sheets("Sheet1").Select
    ActiveSheet.ListObjects("List1").Range.Select
    Selection.ListObject.QueryTable.Refresh Background Query:=FaLse
    AciveSheet.ShowAllData
    Do this:
    With Sheets("Sheet1")
       .ListObjects("List1").QueryTable.Refresh BackgroundQuery:=False
       .ShowAllData
    End With
    These lines of code are probably not causing your problem but something could be happening upstream that you're not showing us that causes it.

+ 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. Macro fix that no longer works.
    By stefano78 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-21-2020, 02:33 PM
  2. [SOLVED] PDF to Email Macro no longer works.
    By TheGomzee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-16-2019, 09:56 AM
  3. [SOLVED] Macro no Longer Works After Row Insert
    By RACoulon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-16-2018, 11:17 AM
  4. Row Delete Macro No Longer Works
    By matt85webb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2015, 04:36 PM
  5. Macro with Sendkeys no longer works
    By barnett2000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-23-2015, 01:15 PM
  6. [SOLVED] Macro no longer works
    By rkorinko in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2014, 01:40 PM
  7. [SOLVED] Help: Excel 4 macro suddenly no longer working
    By Keske Saram in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-03-2005, 10:05 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