VBA Select Case error: procedure too large

angela022687

New Member
Joined
Aug 1, 2014
Messages
6
Hi,

I have 30 different cases working well in one module so far. Now I need to add some more cases, but the system doesn’t allow me to start defining any new cases under Select – Case, it shows: compile error: procedure too large.

I’m thinking maybe there’s a way to combine multiple cases like Case 30, 31, 32 in one statement, and use if, else to define each one?? So the coding won’t return the “Procedure Too Large” error? see my original coding as below:

counter = 0
colkey = 0
For Each cont In PriceForm.HaveFrame.Controls
If TypeName(cont) = "CheckBox" Then
counter = counter + 1
check = cont.Value
If check = True Then
colkey = colkey + 1
Select Case counter
Case 1
have.Add Item:="Product 1", Key:=CStr(colkey)
Case 2
have.Add Item:=" Product 1", Key:=CStr(colkey)
……………
Case 31
have.Add Item:=" Product 31", Key:=CStr(colkey) '''After I added this case, it returned” Procedure Too Large” error
End Select
End If
End If
Next cont

Does anyone know what’s the problem here?

Thanks in advance! :)
 
This may be a silly suggestion, but are you applying the same thing to each case? If so, why not apply multiple cases?

Select Case counter
Case 1 to 31
have.Add Item:="Product name", Key:=CStr(colkey)
End Select

The product name would be the only tricky part for a newbie like myself, but I'm positive it's doable!

the product name is a tricky part for me too if i'm combining all cases into one statement :(
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The advantage of using a multiselect listbox is that you would only be dealing with one control.

Also, it would be straightforward to loop through the items listed in the listbox and see which ones have been selected.

By the way, what are the the captions of the checkboxes?

If it's the products then why not use them in your code?
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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