Embedded Select case too large?

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
349
Office Version
  1. 365
Platform
  1. Windows
I Have a program that a multi-tier select case where the top tier has three choices and each of the second tiers has 5 choices. The code in each of the choices is probably 50-75 lines. When I try running it I get a Compile Error : Procedure too large.

is there a limit to the amount of code that you can have in the select cases?

In order to get around this do I need to remove the 1st tier of the select case and turn it in to three separate If Statements and then run three separate Select case statements?
Excel Formula:
"example Code"

Sub xyz()
    
    Select case variable
    case is = 1
        select case variable2
        case is = A
             'Code
        Case is = B
             'Code
       Case is = C
             'Code
       Case is = D
             'Code
       Case is = E
             'Code
       end select
        'more code'
    case is = 2
        select case variable2
        case is = A
             'Code
       Case is = B
             'Code
       Case is = C
             'Code
       Case is = D
             'Code
       Case is = E
             'Code
       end select
        'more code'
    case is = 3
        select case variable2
        case is = A
             'Code
       Case is = B
             'Code
       Case is = C
             'Code
       Case is = D
             'Code
       Case is = E
             'Code
       end select
        'more code'
    end select

end sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I Have a program that a multi-tier select case where the top tier has three choices and each of the second tiers has 5 choices. The code in each of the choices is probably 50-75 lines. When I try running it I get a Compile Error : Procedure too large.

is there a limit to the amount of code that you can have in the select cases?

In order to get around this do I need to remove the 1st tier of the select case and turn it in to three separate If Statements and then run three separate Select case statements?
Excel Formula:
"example Code"

Sub xyz()
   
    Select case variable
    case is = 1
        select case variable2
        case is = A
             'Code
        Case is = B
             'Code
       Case is = C
             'Code
       Case is = D
             'Code
       Case is = E
             'Code
       end select
        'more code'
    case is = 2
        select case variable2
        case is = A
             'Code
       Case is = B
             'Code
       Case is = C
             'Code
       Case is = D
             'Code
       Case is = E
             'Code
       end select
        'more code'
    case is = 3
        select case variable2
        case is = A
             'Code
       Case is = B
             'Code
       Case is = C
             'Code
       Case is = D
             'Code
       Case is = E
             'Code
       end select
        'more code'
    end select

end sub
Breaking it out into three different If Statements didn't work either. Apparently the issue is with the 2nd tier Select statement.
 
Upvote 0
There is a limit to how much code you can have in one module. It sounds to me like your code needs refactoring and/or redesigning.
 
Upvote 0
I didn't think that I had that much code in my module. Ive had more code in other modules but I will look into reworking the procedure.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top