+ Reply to Thread
Results 1 to 6 of 6

VBA code behaves differently while stepping?

  1. #1
    Registered User
    Join Date
    06-09-2009
    Location
    Capitola, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    VBA code behaves differently while stepping?

    So...I have this code that works flawlessly when I step into each line manually (pressing the F8 key).

    When I create a button and assign the code to the button, I get an error "Code execution has been interrupted" and when I manually press F8 it continues fine....This has never happened before, why this different behavior from the same code?

    Thanks,

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA code behaves differently while stepping?

    Welcome to the forum, mhni .

    So ... can we see the code?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    06-09-2009
    Location
    Capitola, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: VBA code behaves differently while stepping?

    Hello

    Certainly...here it is: There is nothing voodooish about this one, just plain boring copying from FORM sheet into MASTER sheet. I have noticed that when the code interrrupts...it does not consistently interrupt at the same line of code, it seems random and when the line is highlighted by Excel in the code, I press F8 and it carries on....without errors/



    Sub NonValue()
    '

    'Non Valued Inventory
    Sheets("Form").Select
    Range("A47").Select

    Do Until ActiveCell.Value = empty


    Sheets("Master").Select
    Range("A1").End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.Offset(0, 11).Range("A1").Select
    Sheets("Form").Select
    Selection.Copy
    Sheets("Master").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "0"
    ActiveCell.Range("A1:G1").Select
    Selection.FillRight
    ActiveCell.Offset(0, 7).Range("A1").Select
    Sheets("Form").Select
    ActiveCell.Offset(0, 6).Range("A1").Select
    Selection.Copy
    Sheets("Master").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Sheets("Form").Select
    ActiveCell.Offset(0, 2).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Master").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Sheets("Form").Select
    ActiveCell.Offset(0, 3).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Master").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(0, 1).Range("A1").Select
    Sheets("Form").Select
    ActiveCell.Offset(0, 2).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Master").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(-1, -22).Range("A1").Select
    ActiveCell.Range("A1:K1").Select
    Selection.AutoFill Destination:=ActiveCell.Range("A1:K2")
    ActiveCell.Offset(2, 0).Range("A1").Select
    Range("A1").End(xlDown).Select
    Sheets("Form").Select
    ActiveCell.Offset(1, -13).Range("A1").Select
    Loop


    End Sub

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA code behaves differently while stepping?

    Please take a few minutes to read the forum rules, and then edit your post to add code tags.

  5. #5
    Registered User
    Join Date
    06-09-2009
    Location
    Capitola, California
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: VBA code behaves differently while stepping?

    Sorry about that...I am still not clear on how to post code....

    For example...these 3 lines:
    Sheets("Master").Select
    Range("A1").End(xlDown).Select
    ActiveCell.Offset(1, 0).Range("A1").Select


    How would you present them?
    This is for future reference since I found the solution:
    At the beginning of the code, input

    Application.EnableCancelKey = xlDisabled

    That fixed the problem!

    Thanks

  6. #6
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Re: VBA code behaves differently while stepping?

    mhni,

    I had the same problem, your line of code did indeed work. I'm just wondering how it started happening in the first place.

    Anyway, to "wrap code", just highlight all and only the code to wrap, then press the "#" button in the toolbar, it will wrap the code like this...


    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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