compile error:procedure too large

fmunirah2

New Member
Joined
Oct 28, 2010
Messages
5
i hve problem with my vba coding..and i dont know hor to reduce it..plz anyone help me..my interface have too many texboxt


Private Sub ComboBox1_Change()
If ComboBox1 = 1 And ComboBox2 = 1 Then
description.Visible = True
FlowRate.Visible = True
Contaminant1.Visible = True
Contaminant2.Visible = False
Contaminant3.Visible = False
Contaminant4.Visible = False
Contaminant5.Visible = False
Contaminant6.Visible = False
Contaminant7.Visible = False
Contaminant8.Visible = False
Contaminant9.Visible = False
Contaminant10.Visible = False
Label1.Visible = True
cont1.Visible = True
cont2.Visible = False
cont3.Visible = False
cont4.Visible = False
cont5.Visible = False
cont6.Visible = False
cont7.Visible = False
cont8.Visible = False
cont9.Visible = False
cont10.Visible = False
ppm1.Visible = True
ppm2.Visible = False
ppm3.Visible = False
ppm4.Visible = False
ppm5.Visible = False
ppm6.Visible = False
ppm7.Visible = False
ppm8.Visible = False
ppm9.Visible = False
ppm10.Visible = False
D1.Visible = True
D2.Visible = False
D3.Visible = False
D4.Visible = False
D5.Visible = False
D6.Visible = False
D7.Visible = False
D8.Visible = False
D9.Visible = False
D10.Visible = False
D11.Visible = False
D12.Visible = False
D13.Visible = False
D14.Visible = False
D15.Visible = False
D16.Visible = False
D17.Visible = False
D18.Visible = False
D19.Visible = False
D20.Visible = False
TD1.Visible = True
TD2.Visible = False
TD3.Visible = False
TD4.Visible = False
TD5.Visible = False
TD6.Visible = False
TD7.Visible = False
TD8.Visible = False
TD9.Visible = False
TD10.Visible = False
TD11.Visible = False
TD12.Visible = False
TD13.Visible = False
TD14.Visible = False
TD15.Visible = False
TD16.Visible = False
TD17.Visible = False
TD18.Visible = False
TD19.Visible = False
TD20.Visible = False
txtDemFlow1.Visible = True
txtDemFlow2.Visible = False
txtDemFlow3.Visible = False
txtDemFlow4.Visible = False
txtDemFlow5.Visible = False
txtDemFlow6.Visible = False
txtDemFlow7.Visible = False
txtDemFlow8.Visible = False
txtDemFlow9.Visible = False
txtDemFlow10.Visible = False
txtDemFlow11.Visible = False
txtDemFlow12.Visible = False
txtDemFlow13.Visible = False
txtDemFlow14.Visible = False
txtDemFlow15.Visible = False
txtDemFlow16.Visible = False
txtDemFlow17.Visible = False
txtDemFlow18.Visible = False
txtDemFlow19.Visible = False
txtDemFlow20.Visible = False
txtDem1Cont1.Visible = True
txtDem2Cont1.Visible = False
txtDem3Cont1.Visible = False
txtDem4Cont1.Visible = False
txtDem5Cont1.Visible = False
txtDem6Cont1.Visible = False
txtDem7Cont1.Visible = False
txtDem8Cont1.Visible = False
txtDem9Cont1.Visible = False
txtDem10Cont1.Visible = False
txtDem11Cont1.Visible = False
txtDem12Cont1.Visible = False
txtDem13Cont1.Visible = False
txtDem14Cont1.Visible = False
txtDem15Cont1.Visible = False
txtDem16Cont1.Visible = False
txtDem17Cont1.Visible = False
txtDem18Cont1.Visible = False
txtDem19Cont1.Visible = False
txtDem20Cont1.Visible = False
txtDem1Cont2.Visible = False
txtDem2Cont2.Visible = False
txtDem3Cont2.Visible = False
txtDem4Cont2.Visible = False
txtDem5Cont2.Visible = False
txtDem6Cont2.Visible = False
txtDem7Cont2.Visible = False
txtDem8Cont2.Visible = False
txtDem9Cont2.Visible = False
txtDem10Cont2.Visible = False
txtDem11Cont2.Visible = False
txtDem12Cont2.Visible = False
txtDem13Cont2.Visible = False
txtDem14Cont2.Visible = False
txtDem15Cont2.Visible = False
txtDem16Cont2.Visible = False
txtDem17Cont2.Visible = False
txtDem18Cont2.Visible = False
txtDem19Cont2.Visible = False
txtDem20Cont2.Visible = False
txtDem1Cont3.Visible = False
txtDem2Cont3.Visible = False
txtDem3Cont3.Visible = False
txtDem4Cont3.Visible = False
txtDem5Cont3.Visible = False
txtDem6Cont3.Visible = False
txtDem7Cont3.Visible = False
txtDem8Cont3.Visible = False
txtDem9Cont3.Visible = False
txtDem10Cont3.Visible = False
txtDem11Cont3.Visible = False
txtDem12Cont3.Visible = False
txtDem13Cont3.Visible = False
txtDem14Cont3.Visible = False
txtDem15Cont3.Visible = False
txtDem16Cont3.Visible = False
txtDem17Cont3.Visible = False
txtDem18Cont3.Visible = False
txtDem19Cont3.Visible = False
txtDem20Cont3.Visible = False
txtDem1Cont4.Visible = False
txtDem2Cont4.Visible = False
txtDem3Cont4.Visible = False
txtDem4Cont4.Visible = False
txtDem5Cont4.Visible = False
txtDem6Cont4.Visible = False
txtDem7Cont4.Visible = False
txtDem8Cont4.Visible = False
txtDem9Cont4.Visible = False
txtDem10Cont4.Visible = False
txtDem11Cont4.Visible = False
txtDem12Cont4.Visible = False
txtDem13Cont4.Visible = False
txtDem14Cont4.Visible = False
txtDem15Cont4.Visible = False
txtDem16Cont4.Visible = False
txtDem17Cont4.Visible = False
txtDem18Cont4.Visible = False
txtDem19Cont4.Visible = False
txtDem20Cont4.Visible = False
txtDem1Cont5.Visible = False
txtDem2Cont5.Visible = False
txtDem3Cont5.Visible = False
txtDem4Cont5.Visible = False
txtDem5Cont5.Visible = False
txtDem6Cont5.Visible = False
txtDem7Cont5.Visible = False
txtDem8Cont5.Visible = False
txtDem9Cont5.Visible = False
txtDem10Cont5.Visible = False
txtDem11Cont5.Visible = False
txtDem12Cont5.Visible = False
txtDem13Cont5.Visible = False
txtDem14Cont5.Visible = False
txtDem15Cont5.Visible = False
txtDem16Cont5.Visible = False
txtDem17Cont5.Visible = False
txtDem18Cont5.Visible = False
txtDem19Cont5.Visible = False
txtDem20Cont5.Visible = False
txtDem1Cont6.Visible = False
txtDem2Cont6.Visible = False
txtDem3Cont6.Visible = False
txtDem4Cont6.Visible = False
txtDem5Cont6.Visible = False
txtDem6Cont6.Visible = False
txtDem7Cont6.Visible = False
txtDem8Cont6.Visible = False
txtDem9Cont6.Visible = False
txtDem10Cont6.Visible = False
txtDem11Cont6.Visible = False
txtDem12Cont6.Visible = False
txtDem13Cont6.Visible = False
txtDem14Cont6.Visible = False
txtDem15Cont6.Visible = False
txtDem16Cont6.Visible = False
txtDem17Cont6.Visible = False
txtDem18Cont6.Visible = False
txtDem19Cont6.Visible = False
txtDem20Cont6.Visible = False
txtDem1Cont7.Visible = False
txtDem2Cont7.Visible = False
txtDem3Cont7.Visible = False
txtDem4Cont7.Visible = False
txtDem5Cont7.Visible = False
txtDem6Cont7.Visible = False
txtDem7Cont7.Visible = False
txtDem8Cont7.Visible = False
txtDem9Cont7.Visible = False
txtDem10Cont7.Visible = False
txtDem11Cont7.Visible = False
txtDem12Cont7.Visible = False
txtDem13Cont7.Visible = False
txtDem14Cont7.Visible = False
txtDem15Cont7.Visible = False
txtDem16Cont7.Visible = False
txtDem17Cont7.Visible = False
txtDem18Cont7.Visible = False
txtDem19Cont7.Visible = False
txtDem20Cont7.Visible = False
txtDem1Cont8.Visible = False
txtDem2Cont8.Visible = False
txtDem3Cont8.Visible = False
txtDem4Cont8.Visible = False
txtDem5Cont8.Visible = False
txtDem6Cont8.Visible = False
txtDem7Cont8.Visible = False
txtDem8Cont8.Visible = False
txtDem9Cont8.Visible = False
txtDem10Cont8.Visible = False
txtDem11Cont8.Visible = False
txtDem12Cont8.Visible = False
txtDem13Cont8.Visible = False
txtDem14Cont8.Visible = False
txtDem15Cont8.Visible = False
txtDem16Cont8.Visible = False
txtDem17Cont8.Visible = False
txtDem18Cont8.Visible = False
txtDem19Cont8.Visible = False
txtDem20Cont8.Visible = False
txtDem1Cont9.Visible = False
txtDem2Cont9.Visible = False
txtDem3Cont9.Visible = False
txtDem4Cont9.Visible = False
txtDem5Cont9.Visible = False
txtDem6Cont9.Visible = False
txtDem7Cont9.Visible = False
txtDem8Cont9.Visible = False
txtDem9Cont9.Visible = False
txtDem10Cont9.Visible = False
txtDem11Cont9.Visible = False
txtDem12Cont9.Visible = False
txtDem13Cont9.Visible = False
txtDem14Cont9.Visible = False
txtDem15Cont9.Visible = False
txtDem16Cont9.Visible = False
txtDem17Cont9.Visible = False
txtDem18Cont9.Visible = False
txtDem19Cont9.Visible = False
txtDem20Cont9.Visible = False
txtDem1Cont10.Visible = False
txtDem2Cont10.Visible = False
txtDem3Cont10.Visible = False
txtDem4Cont10.Visible = False
txtDem5Cont10.Visible = False
txtDem6Cont10.Visible = False
txtDem7Cont10.Visible = False
txtDem8Cont10.Visible = False
txtDem9Cont10.Visible = False
txtDem10Cont10.Visible = False
txtDem11Cont10.Visible = False
txtDem12Cont10.Visible = False
txtDem13Cont10.Visible = False
txtDem14Cont10.Visible = False
txtDem15Cont10.Visible = False
txtDem16Cont10.Visible = False
txtDem17Cont10.Visible = False
txtDem18Cont10.Visible = False
txtDem19Cont10.Visible = False
txtDem20Cont10.Visible = False

.....this repeat 20 time sinse i hve 20 string in combobox
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Wow is this for real? i would love to look into your actual workbook....:)
 
Upvote 0
That code could be reduced substantially by using the Controls collection of the combobox, but I really don't think having so many controls on one form is
practical.

You also seem to be repeating a whole lot of things, have you considered using Listboxes?

Anyway here's the sort of code you would need to deal with all those controls.
Code:
Dim I As Long
Dim J As Long

    For I = 1 To 10
        Me.Controls("Contaminant" & I).Visible = False
        Me.Controls("cont" & I).Visible = False
        Me.Controls("ppm" & I).Visible = False
    End If
 
    For I = 1 To 20
        Me.Controls("D" & I).Visible = False
        Me.Controls("TD" & I).Visible = False
        Me.Controls("txtDemFlow" & I).Visible = False
    Next I
 
    For I = 1 To 10
        For J = 1 To 20
            Me.Controls("txtDem" & J & "Cont" & I).Visible = False
        Next J
    Next I
 
    Description.Visible = True
    FlowRate.Visible = True
    Label1.Visible = True
    Me.Controls("Contaminant1").Visible = True
    Me.Controls("cont1").Visible = True
    Me.Controls("ppm1").Visible = True
    Me.Controls("D1").Visible = True
    Me.Controls("TD1").Visible = True
    Me.Controls("txtDemFlow1").Visible = True
    Me.Controls("txtDem1Cont1").Visible = True
I say 'sort' of because I've got a feeling this won't work straight off.

Also I'm pretty sure you want to do something with the values from the comboboxes or some other controls.

If you explain what you are actually trying to do I think you might get a few suggestions.:)
 
Upvote 0
moz-screenshot-6.png
moz-screenshot-7.png
actually im doing optimization of water..
erm..how to insert image?i wnt to share the print screen of my wrkbook..so that u cn imagine what im trying to do..:)
 
Upvote 0
I did say the code I posted would be unlikely to work straight off.

How exactly did you try to use it?

Though a screenshot might help, an explanation in words might be better.

I'm not even sure you could post an representative image of a useform with almost 300 controls on it, especially when it seems the majority are hidden.:)
 
Upvote 0
i have 2 combobox.combobox1 and combobox2. combobox1 have 20 value, and combobox2 have 10 value..
for exmple,when user choose value 1 in combobox1,and value 1 of combobox2 only selectd text box are visible..the textbox visible base on the value chosen from the two combobox,.all the text box are visible when user chose value 20 in combobox1 and value 10 of combobox2

D,TD,texdemflow..etc..are the textbox..
 
Upvote 0
Eh, perhaps I wasn't clear.

Why do you have all these textboxes?

Whatever it is, and I am starting to get some ideas, that just doesn't seem practical.

If you want the user to select a number from a combobox that then allows them to enter a set amount of data using
these textboxes there are definitely better ways to do it.

For example you could work with only 1 textbox each for contaminant, ppm, D, TD etc.

The user enters data into these textboxes and hit's a command button.

That command button transfers the values entered into a listbox and 'resets' the textboxes for further input.

The user could enter as many sets of data as they want, or up to a set limit determined by what's chosen in a combobox.

Does that make any sense?

I'm almost 100% sure it doesn't do exactly what you want but since I don't know what that is I think it's a fair shot at it...:)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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