+ Reply to Thread
Results 1 to 8 of 8

MAcro works OK in Step into debug mode but not doing job when run from command button

  1. #1
    Forum Contributor
    Join Date
    12-25-2011
    Location
    Lahore, Punjab, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    287

    MAcro works OK in Step into debug mode but not doing job when run from command button

    I have macro that runs OK when run by continually pressing F8 key and imports about 100 rows

    However when I run with command button, it only imports 2 lines and then stops imemdiately without any error.

    Please Login or Register  to view this content.
    Last edited by caabdul; 03-10-2018 at 11:34 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button

    You are using select and active sheet and when you run the code, it picks the sheet names wherever the cursor happens to be, not necessarily the correct sheet name. You need to properly reference your sheet names and range.
    It is also faster to use a filter function than a loop.

    Please Login or Register  to view this content.

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

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button


    Hi !

    Better & faster execution just using a filter or an advanced filter …

  4. #4
    Forum Contributor
    Join Date
    12-25-2011
    Location
    Lahore, Punjab, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button

    Hi AB33

    I did this;

    Please Login or Register  to view this content.
    and also put
    Please Login or Register  to view this content.
    but it doesn't help. Even when I run macro from Visual Basic window's Run button, it works.

  5. #5
    Forum Contributor
    Join Date
    12-25-2011
    Location
    Lahore, Punjab, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button

    ah, I forgot to remove "ws.Activate", in "With ws" section. It works Now. Thanks

  6. #6
    Forum Contributor
    Join Date
    12-25-2011
    Location
    Lahore, Punjab, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button

    Same problem happening to another code. Code won't run using button in sheet. What is issue in it now?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button

    In the application.Sum part you have to specify which sheet you want this to be executed.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Forum Contributor
    Join Date
    12-25-2011
    Location
    Lahore, Punjab, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    287

    Re: MAcro works OK in Step into debug mode but not doing job when run from command button

    It worked, Thanks

    I changed all 4 instances of .Sum to ....Sum(.Sheets("Shifts").Range......
    Last edited by caabdul; 03-10-2018 at 11:34 AM.

+ 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. Single step works fine but command button has errors
    By CptCrunch51 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2017, 01:07 PM
  2. [SOLVED] VBA code works in debug mode but misses steps running in normal mode
    By supereeg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2016, 05:42 AM
  3. [SOLVED] A command button that works while in manual mode??
    By TDeRanger in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-12-2014, 07:14 AM
  4. VBA code only works correctly in Debug mode
    By tpthatsme in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2012, 12:51 PM
  5. Macro Works but not in Debug Step mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2006, 12:35 PM
  6. How show value of variable by mouse-over in debug single step mode
    By Chet Shannon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-06-2006, 11:35 AM
  7. [SOLVED] How show value of variable in single step debug mode?
    By Chet Shannon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2005, 03:00 AM

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