VBA Program skipping lines of code RRS feed

  • Question

  • Hello,

    I have encountered a weird problem at work where a VBA program is skipping lines of code when used on all of the computers in the office but mine. The program is designed to copy data from one excel file to another. I know that it is skipping lines because there are no logic test that may prevent the code from running and the breakpoints are not triggering. I've tried placing breakpoints on those same lines on my computer, and they trigger just fine.

    I can't really post those bits of code as they contain proprietary information, and I do apologize for that. I am wondering if anyone have experienced anything similar though. Any help or ideas would be helpful though. Thank you!

    Best Regards,

    Parco Lai

    Tuesday, February 14, 2017 5:42 PM

All replies

  • Parco, 

    Often, the way that errors are trapped can be responsible for this behavior - you may have the option "Break on all errors" and they may break on unhandled errors.

    It could be a reference difference, or a difference in paths to the files required.

    Have you tried stepping through the code on one of the 'weird' machines?

    Tuesday, February 14, 2017 9:11 PM
  • Hi Bernie,

    Yes I have tried stepping through the code on those "weird" machines. That's how I know that it is skipping lines on those machines.

    Wednesday, February 15, 2017 9:35 PM
  • What is the last line fully executed before the skipping occurs? What is the first line that is not fully executed?
    Wednesday, February 15, 2017 10:16 PM
  • Is there an On Error command o are you triggering an event.  VBA does not skip code unless there is an error, conditional statement  or you have an event.
    Wednesday, February 15, 2017 11:32 PM
  • Remove below instruction (if you have one)

    on error resume next

    Than You can run your code StepByStep using [F8] and klick on the left bar add the breaking point, there code 'll stop when you run it as usual [F5]

    Good practise is using to every module and form instruction line: Option Explicit

    After this check in VBA option, this line 'll be add automaticly

    Then You code calling you to make good declaration variables.

    Oskar Shon, Office System MVP -
    if Helpful; Answer when a problem solved

    Thursday, February 16, 2017 8:31 AM
  • Okay, now we're getting somewhere. I tried doing what you suggested on one of the "weird" computers. This time, there's an error message that says " runtime error 40036 application defined or object defined error".

    It popped on this line: mySheet.Range("B" & InputRow) = testWB.Sheets("Config Sheet").Range("F18").Value

    Thursday, February 16, 2017 10:22 PM
  • I prefer a different way to address sheets/cells.

    Dim ws as Worksheet
    Dim ws2 as Worksheet

    Set ws = Worksheets("Config Sheet")
    Set ws2 = Worksheets("Other Sheet")

    ws.cells(1, 2) = ws2.cells(i, 3)

    This way if you change sheet names you only need to change one line.  I worked on a joint project one time and we agreed this was the easiest method to understand and communicate.  This was especially true for non VBA programmers (PERL, Ruby, Java etc).

    Thursday, February 16, 2017 10:48 PM
  • I don't think that's the problem, as the sheet name on the coded matches the one on the workbook I'm copying from. And it doesn't explain why I experience the problem I'm experiencing on all but one computer. I'll change that when I have nothing else to do.
    Thursday, February 16, 2017 11:10 PM
  • Have you used   Debug / Compile VBA Project ?
    Thursday, February 16, 2017 11:19 PM
  • Yes. I've tried that too. No Error came up at compile. I tried commenting out one line and the de-comment it again, then compile. No error came up.
    Thursday, February 16, 2017 11:38 PM
  • If you have line: 

    On Error Resume Next

    in youre code that you want to skipping any errors.

    I sugesting you a Braking Point and StepByStep usung [F8] to follow each code line

    Oskar Shon, Office System MVP -
    if Helpful; Answer when a problem solved

    Wednesday, February 22, 2017 9:53 AM