+ Reply to Thread
Results 1 to 7 of 7

Macro only works step-by-step

  1. #1
    Registered User
    Join Date
    10-01-2019
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    73

    Macro only works step-by-step

    Hi everyone. I have a macro that works step-by-step but not when run fully. I found the portion of the code where the issue lies. The value for count needs to be equal to 3 in this specific run of the macro. I checked and count does in fact equal 3, however, it is behaving as if count was equal to 1. When I replace count with the number 3 in my code, it works. Can anyone explain this to me?

    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    01-29-2020
    Location
    Kraków, Poland
    MS-Off Ver
    Office 365
    Posts
    10

    Re: Macro only works step-by-step

    Hello smw10c,

    The code you have posted looks OK and the only thing that can make this code work "as if count was equal to 1" is that your loop condition is only valid for one run.
    You might want to attach your sample sheet and get deeper into what you want to achieve and what is happening instead upon running the macro.

    Regards,
    Buskolsky

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro only works step-by-step

    Hi,

    I've found the cause for this sort of thing is that when you step through the macro the sheet that contains the macro is active and everything is fine, but when you run the macro from another sheet there is a conflict.

    Please upload the workbook so that we can see the [roblem in context.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Macro only works step-by-step

    This is not a macro but a fragment of it, this is evidenced by the lack of: header and end of procedure, variable declarations (rng1, Arr/Arr(), count) and occurrence an excessive, redundant "End If" clause - by the way: "Count" is a "component" of the vba language, see contextual help ("Count" Property/collection). What does the data layout on which this code is to work look like ?

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Macro only works step-by-step

    Hi there,

    Firstly, you have an unpaired End If statement in your code, but I'll assume that the corresponding If statement just "fell by the wayside" when you were copying your actual code to the post.

    Secondly (and more importantly), this statement will fail if Sheet(2) is not the active sheet when the code is running, but this failure will be hidden by the On Error Resume Next statement in the preceding line. This can be overcome by inserting the highlighted line.

    In general you should always include an On Error GoTo 0 (or equivalent) statement as close as possible to the On Error Resume Next statement - this will ensure that errors occurring later in the code are not unintentionally hidden.

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  6. #6
    Registered User
    Join Date
    10-01-2019
    Location
    Miami, Florida
    MS-Off Ver
    2016
    Posts
    73

    Re: Macro only works step-by-step

    First off, thank you everyone. I don't want to blow up your notifications by responding to each and every one. Richard and Greg were spot on. This completely worked. If you don't mind me asking, why does it need to be activated at that point in time?

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Macro only works step-by-step

    Hi again,

    Many thanks for your very prompt feedback and also for the Reputation increase - much appreciated.

    The ActiveCell is a child element of the ActiveSheet (not all that surprising really! ), so if you don't activate the specific worksheet you need, the ActiveCell will be taken from whichever worksheet happens to be active when the code is running.

    I fully agree with Richard's comment and have found this to be the case in many of the requests for help here. In fact, when I read "it works on a step-by-step basis" I immediately start looking for references which are not fully qualified, and in 99.9% of cases I find them

    Hope this helps,

    Best regards,

    Greg M

+ 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. Replies: 1
    Last Post: 07-11-2019, 12:52 PM
  2. Macro errors when running, but works when done step by step
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2018, 03:54 PM
  3. Replies: 2
    Last Post: 01-11-2017, 12:24 AM
  4. VBA Code works by step by step, doesn't work by running
    By lucasar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2016, 06:33 AM
  5. [SOLVED] Macro works in step through but not when run
    By bruizer31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2013, 05:50 PM
  6. [SOLVED] preventing simple zoom macro from running step by step
    By reece1984 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-11-2012, 06:13 AM
  7. [SOLVED] I need step by step instructions to create a macro for 10 imbedde.
    By diana in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-30-2005, 10:06 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