Excel VBA "For loop" does not respond

%3CLINGO-SUB%20id%3D%22lingo-sub-1633107%22%20slang%3D%22en-US%22%3EExcel%20VBA%20%22For%20loop%22%20does%20not%20respond%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1633107%22%20slang%3D%22en-US%22%3E%3CP%3EI%20had%20a%20problem%20debugging%20a%20VBA%20program.%26nbsp%3B%20I%20could%20not%20step%20into%20a%20%22For%20loop%22.%26nbsp%3B%20I%20wrote%20a%20simple%20loop%20to%20see%20if%20the%20problem%20was%20persistent.%26nbsp%3B%20This%20file%20is%20attached.%26nbsp%3B%20When%20I%20open%20Module1%20and%20attempt%20to%20step%20into%20the%20macro%2C%20I%20get%20the%20error%20message%20below.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jdebaise_0-1599162094295.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216369i884001639DC73EA9%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22jdebaise_0-1599162094295.png%22%20alt%3D%22jdebaise_0-1599162094295.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EI%20don't%20care%20about%20the%20macro.%26nbsp%3B%20I%20care%20the%20macro%20will%20not%20run%20and%20that%20I%20can't%20step%20into%20it%20to%20debug%20it.%26nbsp%3B%20I%20am%20sure%20you%20will%20be%20able%20to%20do%20so.%26nbsp%3B%20My%20VBA%20is%20corrupted%20or%20something%20and%20I%20don't%20know%20how%20to%20fix%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20VBA%20is%20not%20the%20most%20stable%20platform.%26nbsp%3B%20When%20I%20had%20problems%20like%20this%2C%20I%20would%20reload%20Excel%20and%20the%20problems%20would%20go%20away.%26nbsp%3B%20This%20time%2C%20I%20reloaded%20Office.%26nbsp%3B%20But%20the%20problem%20persists.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJohn%20DeBaise%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1633107%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1633184%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20VBA%20%22For%20loop%22%20does%20not%20respond%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1633184%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F781467%22%20target%3D%22_blank%22%3E%40jdebaise%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20macro%20is%20a%20piece%20of%20code%20that%20begins%20with%20Sub%20%3CEM%3Emacroname%3C%2FEM%3E()%20and%20ends%20with%20End%20Sub.%3C%2FP%3E%0A%3CP%3EBoth%20are%20missing%20from%20your%20code.%3C%2FP%3E%0A%3CP%3EIt%20should%20look%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20Test()%0A%20%20%20%20Dim%20i%20As%20Integer%0A%20%20%20%20For%20i%20%3D%200%20To%2010%0A%20%20%20%20%20%20%20%20Range(%22A1%22).Select%0A%20%20%20%20%20%20%20%20Selection.End(xlDown).Select%0A%20%20%20%20%20%20%20%20Selection.Offset(1%2C%200).Select%0A%20%20%20%20%20%20%20%20Paste%0A%20%20%20%20Next%20i%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20will%20then%20be%20able%20to%20step%20into%20the%20code%20etc.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

I had a problem debugging a VBA program.  I could not step into a "For loop".  I wrote a simple loop to see if the problem was persistent.  This file is attached.  When I open Module1 and attempt to step into the macro, I get the error message below.

jdebaise_0-1599162094295.png

I don't care about the macro.  I care the macro will not run and that I can't step into it to debug it.  I am sure you will be able to do so.  My VBA is corrupted or something and I don't know how to fix it.

 

I know VBA is not the most stable platform.  When I had problems like this, I would reload Excel and the problems would go away.  This time, I reloaded Office.  But the problem persists.

 

John DeBaise

1 Reply

@jdebaise 

A macro is a piece of code that begins with Sub macroname() and ends with End Sub.

Both are missing from your code.

It should look like this:

 

Sub Test()
    Dim i As Integer
    For i = 0 To 10
        Range("A1").Select
        Selection.End(xlDown).Select
        Selection.Offset(1, 0).Select
        Paste
    Next i
End Sub

 

You will then be able to step into the code etc.