+ Reply to Thread
Results 1 to 3 of 3

"sub too long" error ? what can i do ?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    "sub too long" error ? what can i do ?

    So i've spent all day working on my user interface, thanks to alot of help from you guys, and just a few minutes ago i got the "sub too long" error... i'm not sure if there is an easier way to do what i'm trying to do with my userform, but here's the situation...

    teacher selects name from combobox1, which then populates a list of classes in combobox 2. the selection of combo box 2 highlights the frames on the userform corresponding to the students in the class... there are 12 frames in total...

    hoping to make my userform as user-error-free as i can, i coded it such that there is code for each frame (and the corresponding 9 option buttons and labels within) to either stay default color, or turn completely red...

    so there is alot of code going on... it does exactly as i intend it to, but now i'm getting a compile error only about 70% of the way through all the classes...

    any thoughts ? i could post some code or pix of the userform if it helps.

    thanks so much everyone !

    -rob

  2. #2
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: "sub too long" error ? what can i do ?

    Hi

    The limit for procedures in Excel is 64k lines of code and above that you will get a compile error.

    Without seeing any code it is difficult to comment, but is it necessary to code each item individually, could you not loop through them and apply the formatting?

    Regards

    Jeff

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: "sub too long" error ? what can i do ?

    I can't imagine any code that can't be broken up into smaller subs.
    Inside your long sub you should be able to find a stretch of code that can stand by itself. Just put all that code into a separate sub and call it from your main sub.

    Sub Sub_1()
        'Line 1
        'Line 2
        'etc.
        'Line 39
        If <sometest> then
            'Line 41
            'Line 42
            'etc.
            'Line 87
        Else
            'Line 89
            'etc.
            'line 107
        End If
        'More Lines
    End Sub
    Convert to:
    Sub Sub_1()
        'Line 1
        'Line 2
        'etc.
        'Line 39
        If <sometest> then
            Sub_2
        Else
            Sub_3
        End If
        'More Lines
    End Sub
    Sub Sub_2
        'Line 41
        'Line 42
        'etc.
        'Line 87
    End Sub
    Sub Sub_3
        'Line 89
        'etc.
        'line 107
    End Sub
    You'll probably need to pass parameters or make public variables or make Sub_2 and Sub_3 into functions. But it cant be done.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

+ 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