Consulting

Results 1 to 6 of 6

Thread: Function, compile error.

  1. #1

    Function, compile error.

    Hi.
    i get this error when i try to run this function. Compile error: procedure too large.

    Im probably over the 64k limit(?), but i need to run this code. It inserts components into a list based on selections from a userform. the code in the attachment is only 1/20 of the total code but it is this spesific function that chrashes.

    I need some help on how to make it run. if i can split it some how, or can i use some procedure inside the function to make it run?

    i tried to split it at case 19 with a new function, but then it would not work past case 19.

    im new to VBA and im lost.
    Attached Files Attached Files

  2. #2
    That seems like something that really screams for a re-design.

    In my humble opinion, you have too much hard-coded data in your code.

    I think it would be better to move out all the hard-coded data to e.g. tables on worksheets and then use logic to decide what piece of data you need to copy from those tables, based on the choices made on the form.

    It will make your code a lot more compact and at the same time makes maintaining the information a lot easier.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    i appresiate the input but i need to run this code. it is to big of a job for me to rewrite with my limited experience. if there is no other option i must hire a pro, but if it is possible to do something(fairly easy) to it that will let it run,i would rather do that.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    We can offer you advice and direction on how to reduce it, but it is too big a job to expect us to recut the function for you, it would take a long time.

    You say function, you don't hope to call this from a worksheet as a UDF do you?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    it is combobox2 in my userform that lists several options for the user. as they select i have a function that makes cases based on the value in the combobox. That again puts the info that is hardcoded into an inventory list.

    Maybe i can devide the function in two? case 13 to 19 etc and then make some code that looks at the value the user selects in the combobox and from this say something like value greater than case 19 go to function "part two"(case 19 to 28).

    That is my idea....... its poorly explained........think i will go job hunting now.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It needs a more fundamental change than that in my view. Every option is basically doing the same, injecting some row headings and a matrix of headings, but differing values depending upon the selection.

    As such, my advice would be to start by building a generic function to populate the cells, then call that function with your different data. There is a ton of redundancy in your code, that looping looking for an empty cell is totally unnecessary, all the selecting, and so on, so my suggestion would cut it down dramatically.

    Then you should consider Jan Karel's suggestion, put all of the values on a worksheet, and load the actual sheets from there. This would ease maintenance and reduce the code to some tens of lines.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •