+ Reply to Thread
Results 1 to 5 of 5

Slow code- making code more efficient

  1. #1
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Slow code- making code more efficient

    Hello. I added this code to about 200 cells in a tab. =IFERROR(HLOOKUP($B16,INDIRECT("'"&TEXT(EOMONTH("12/31/2012",COLUMN(F16)+ROW(F16)-7),"mmmm yyyy")&"'!"&"$C$2:$O$35"),34,FALSE),0)

    Now, my workbook is running very slow. When I ran a macro that worked perfectly before, it froze up. I think that has to do with these formulas. The formulas look for different tabs in the workbook and then do an hlookup. Is there a more effecient way of writing this formula?

  2. #2
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Slow code- making code more efficient

    Do you mind posting your VBA code and sample workbook as well?

    The trick is to get rid of the INDIRECT, as it is volatile. I realize one of your other threads was about whether INDIRECT was needed, but that thread did not have the context of what your end-goal is.

    The way I see it, you seem to be writing this formula in a cell, then copying/filling down. If the cells do not shift around after that (meaning no cut/paste or insert/delete) then these values are more or less static, and so can be generated without INDIRECT some way. I believe the best approach, without having seen your workbook or knowing your end-goal, is to loop through the cells in question and write a less volatile formula into them, taking advantage of VBA's power and flexibility.

  3. #3
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Slow code- making code more efficient

    Ok, I just copied one tab (the other info is confidential). It has the lookups (they don't return anything because the tabs have been taken out). Why is the indirect volatile? Please let me know how to improve. Thanks.
    Attached Files Attached Files

  4. #4
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Slow code- making code more efficient

    It is volatile becuase you are asking Excel to interpret a string as a reference. This means, to Excel, that the string could change at any time, so must recalc every time there is a change in the workbook. This slows things down when you have lots of INDIRECTs.

    Can you provide the basic structure of the other worksheets? I assume they are all the same, just different data. If so, it might be beneficial to have them all on one table and then have a monthly summary sheet or something that displays the month's data using formulas and a selection tool of some sort. This will limit the number of sheets and eliminate the need for INDIRECT.

    Also, Can I see your VBA code? Here is how I would write it, not knowing exactly what you need it for.

    Please Login or Register  to view this content.

    Oh, and want to learn another trick?

    Please Login or Register  to view this content.
    This will give you the end of month for the month prior to A1. EOMONTH works just fine, but this is another trick. You can do things like "=Date(Year(A1),Month(A1)+6,0)" to shift months around. I find it easier to read than EOMONTH, but that is just a preference. It also works on all versions of Excel.
    Last edited by Whizbang; 05-05-2015 at 04:37 PM.

  5. #5
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Slow code- making code more efficient

    This is how I would do it.
    Attached Files Attached Files
    Last edited by Whizbang; 05-06-2015 at 03:32 PM.

+ 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. Making range delete code more efficient
    By Geoff. in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-17-2014, 04:59 PM
  2. Making Code More efficient
    By SHUTTEHFACE in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-15-2014, 06:07 PM
  3. Help needed on making code more efficient
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2011, 07:49 AM
  4. making code more Efficient !!! please help
    By virgiliocabrera in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2011, 09:09 PM
  5. making code more efficient
    By JChandler22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2008, 05:11 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