+ Reply to Thread
Results 1 to 12 of 12

Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

  1. #1
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Hi,

    I have the following code as part of more code within "Sheet1" Module using the Worksheet_Calculate() command.


    Please Login or Register  to view this content.


    Because i have so much code within "Sheet1" its returning "Procedure Too Large" compile error.

    I have already optimised as best i can calling for Macros in separate Modules but still need to condense this.


    I'm sure there is someway to combine into ONE multiple IF , AND, OR statement, im just not advanced enough to know how!

    Andy help greatly appreciated guys!

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Your code has given me a headache
    Is Call Module_E is affecting the values each time it runs?

    You could relieve pressure on the VBA by doing part of the checking within the worksheet itself
    You are making VBA work very hard repeating itself
    - (as far down as I looked) this seems to be in every condition
    Please Login or Register  to view this content.
    How about using ONE cell with the formula that would return TRUE/FALSE if all those conditions met?
    - that snippet of VBA would then reduce to
    Please Login or Register  to view this content.
    Will that work? - or am I missing something? (it may be that there are too many subtle variations in the tests)
    Are there any other similar multiple tests that could be performed by simple Excel formula?


    The macro is very repetitive in general and so you could create one or two small macros and run them repetitively passing different values to them each time - this would have a huge impact
    Last edited by kev_; 03-21-2018 at 01:22 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Hi,

    You should also know that your error handling will only work for one error. Any further errors will not be handled as you have not used a Resume statement.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Sorry guys! Basically im self taught for less than a year and i guess im coding a way which my mind works (not necessarily the best way at all!)

    Ill try that now in a cell and check that in VBA, good idea!

    Also,

    Where do i put the 'Resume' Statement to get my error handler to work? Basically i have more code on that sheet! (i know!) and it goes through all the conditions and if error goes to next set conditions at the end it goes back to the top. I do this as the cells its checking are constantly updating from an API data source.

    Thanks for your help guys!

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    There is, in my opinion, no good way to add error handling to that. The whole code needs restructuring and refactoring.

    I'm not sure what this is supposed to do
    Please Login or Register  to view this content.
    Do you have merged cells, or are you trying to compare one value to an array?

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Looking again at your code, this would be one suggestion
    - create a sub to validate the values and call it in each section

    Must be placed in the same module as MainSub
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Anything that has not changed can be used again without repeating

    Also range position PATTERNS may help avoid endless repeating of lines of code
    - above I used the ranges as used by you, but there are relationships between consecutive range uses
    - If there are patterns then it is possible to avoid repeating some of the code
    eg
    Set rng6 = Range("AH10") then becomes AH12 and AH14 etc so you can use
    Set rng6 = rng6.Offset(2) after the first time and it will be offset by 2 more rows each time
    If rows increment by 2 EVERY time then that line can be placed ONCE in MiniSub and it will increment automatically every time MiniSub is run

    Time to step back and take a long hard look at everything
    - can the worksheet take some of the validation burden?
    - look for patterns and use them to minimise repeating code

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    At a very basic level you could move
    Please Login or Register  to view this content.
    into a separate routine called from each If block, then simply put On Error Resume Next at the start of this section and On Error Goto 0 at the end. Additionally, you seem to be repeating some of the criteria, so you should put those into a separate If clause
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Ahhh! you guys are right i need to completely re-structure... i'm learning a lot though so thank you!

    For;

    Please Login or Register  to view this content.
    I'm trying to ask - IF Cell AA1 is in ANY of the Cells AA71:AA77 as a condition. Is this not right as this is vital at the start of my IF statement?

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    No, that won't work at all. You could use this
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Yes that works thank you!

    This is what i have now in a helper column (as suggested);

    Please Login or Register  to view this content.
    You can see that i still have the code that wont work in there. Using your IsError method, how can i combine that formula with mine?

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    You could use
    =IF(OR(AND(COUNTIF($AA$71:$AA$77,$AA$1)>0,...

  12. #12
    Forum Contributor
    Join Date
    02-09-2016
    Location
    West Midlands
    MS-Off Ver
    2016
    Posts
    224

    Re: Worksheet_Calculate() - Procedure Too Large... How to combine multiple conditions?..

    Sorry for late reply!

    Perfect... as always xlnitwit (Rep Left ) Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Issue with LARGE, MATCH, INDEX and duplicates, multiple conditions
    By Toddowhams in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-05-2017, 03:08 PM
  2. [SOLVED] How to combine multiple worksheets of text data into one large worksheet?
    By drgreenjr in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-20-2016, 03:09 PM
  3. large function multiple conditions
    By jaredf in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-25-2016, 12:49 PM
  4. LARGE Function with multiple conditions
    By andrewc in forum Excel General
    Replies: 5
    Last Post: 08-20-2014, 11:40 AM
  5. Combine data from multiple sheets with conditions
    By luckyk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-28-2012, 11:20 AM
  6. Combine multiple INDEX/Match conditions
    By rlsublime in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-06-2011, 01:52 PM

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