+ Reply to Thread
Results 1 to 7 of 7

Code Runs Perfectly When I Step Through It but when I run it normally it skips procedures

  1. #1
    Registered User
    Join Date
    03-01-2014
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    3

    Code Runs Perfectly When I Step Through It but when I run it normally it skips procedures

    Hi everyone,

    First of all, sincere apologies if this post is less than stellar, but I am very new to VBA.

    I'm currently working on a piece of code that runs 1000 times. Every 10th time the code runs it kicks off another procedure which prints a line on a sheet when it is finished. When I step through the code everything is fine but when I run the procedure that kicks off ever ten times only runs a few times, instead of 100 times. When I change the parameters to 20000 runs and have the procedure every 500 times it works correctly. It's almost as if when I run the code in smaller increments it runs too quickly. As if the code keeps running before the line gets printed.

    I'll post the code shortly but has anyone seen anything like this before?

    Thanks in advance for the help.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Code Runs Perfectly When I Step Through It but when I run it normally it skips procedu

    Hi Miguel and welcome to the forum.

    It sounds to me like you need some
    DoEvents in your code.

    I'd put them just after the line that sends stuff to the printer. The idea is you need to let windows to do other things (send stuff to the printer) before the code keeps running. The DoEvents tells VBA to wait for windows to come back to it before proceeding with your vba code.

    http://support.microsoft.com/kb/118468
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Code Runs Perfectly When I Step Through It but when I run it normally it skips procedu

    @marvinp

    that is a great tip, haven't followed the link yet but I am thinking, "this goes down in the lessons learned" pile, thanks for your experience yet again

    Jmac

  4. #4
    Registered User
    Join Date
    03-01-2014
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Code Runs Perfectly When I Step Through It but when I run it normally it skips procedu

    Hey Marvin,

    I attempted the DoEvents to no avail. Below is the code, which at this point is driving me crazy. Hope it's not too long and thanks again for taking a look everyone.


    Please Login or Register  to view this content.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Code Runs Perfectly When I Step Through It but when I run it normally it skips procedu

    Hi Miguel,

    Put an "Option Explicit" as the first line in your module. That will make sure all your variables are defined. I don't see where a variable of "Running" is defined.

    I really need to know where the code stops or crashes.

    Because you are sending stuff to a printer, based on your description above, it could be a Printer memory problem. That is that the printer has a buffer that holds pages to be printed and you are sending it more than it can hold. Look at your printer documentation to see if it can communicate back to the computer and/or the computer can wait until the printer can accept more data.

    Something like:
    http://support.microsoft.com/kb/123485 or
    http://support.microsoft.com/kb/92484

  6. #6
    Registered User
    Join Date
    03-01-2014
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Code Runs Perfectly When I Step Through It but when I run it normally it skips procedu

    Her Marvin thanks again. Sorry for having used the word print. I meant that certain values get placed on a spread sheet every time CheckTimeTrade runs. I will put the Option Explicitin when I get home as well as properly spell out all the variables so you can see it all as it should be.

    Again, thanks for trying to help. Means a ton.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Code Runs Perfectly When I Step Through It but when I run it normally it skips procedu

    If you are pulling data from a website and putting them into your workbook (and not sending them to a printer, like I assumed) this is more information.

    I'm going back to my DoEvents answer or that the wrong sheet is the active sheet when you are trying to deal with the correct data.

    This may come down to those darn "With Dots"!!

    I only know this because I've screwed this up many times.. The idea is this ...

    You will be looking at Sheet1 and the code will say:

    With Worksheets("Sheet2")
    Range(Cells(1,"A"),Cells(5,"B"))
    End With

    vs

    With Worksheets("Sheet2")
    .Range(Cells(1,"A"),Cells(5,"B")) ' Note the extra period (a small change in this line). This says to use sheet2 info
    End With

    vs

    With Worksheets("Sheet2")
    .Range(.Cells(1,"A"),.Cells(5,"B")) ' Three dots here, now use cells from sheet2 also. In above it used sheet1 Cells..
    End With

    I'm completely guessing the above is a problem, but I've stepped into this "dot" mess a few times with no answer before. The dot is so small but it means SO much. It is similar to the dollar sign in cell referencing.

    Perhaps the above is your problem in that you are doing code to the wrong sheet..??

+ 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. [SOLVED] Code skips on Run Mode but runs fine on F8 (Debug Mode)
    By RaquelAR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2013, 01:05 PM
  2. [SOLVED] Excel 2007 - VBA code working perfectly on sheet 1 but not on the rest of the sheets
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-25-2013, 06:22 PM
  3. [SOLVED] Macro runs perfectly, but dialog box doesn't close automatically
    By Bunnyla in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-29-2012, 01:12 PM
  4. Macro runs fine when I step through with F8, but crashes Excel when I run it
    By ncalkins in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 09:18 PM
  5. Code runs when I step through it, but not when I run the whole program
    By gonger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-11-2010, 12:34 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