+ Reply to Thread
Results 1 to 9 of 9

Creating a macro to replace a formula that takes forever to calculate

  1. #1
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Creating a macro to replace a formula that takes forever to calculate

    Hi All,

    I have the following formula that returns a specific value
    Please Login or Register  to view this content.
    At first it worked great, but unfortunately the data increased over time, now being at 50k rows and counting. Running the formula takes forever to calculate and sometimes it crashes.
    I think that the best way to handle this would be a macro, but I have no ideea how to get started and create one.
    Looking for help.

    Thnaks in advance,
    Paul
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Creating a macro to replace a formula that takes forever to calculate

    Your sample has expected output, but it is not clear what info is being looked up. I'd suggest you upload sample that has not just the result, but all necessary data to perform calculation. Clearly indicating what column should hold the result etc.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,735

    Re: Creating a macro to replace a formula that takes forever to calculate

    Why don't you concatenate H2 and V2 in a helper column, copied down, then you wouldn't need to do it within the formula?

    Hope this helps.

    Pete

  4. #4
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Creating a macro to replace a formula that takes forever to calculate

    Hi CK76. The logic ibehind the formula is: if the title found in column V is duplicated, then it looks up the Training type found in Column V. If the same title exists for both Session and Event, then it should return only the ID(column W) that belongs to the Event disregarding the Session's ID. The results should be returned in column BC. I added the Expected results in the next column for a better understanding. I hope it is clear.

    Why don't you concatenate H2 and V2 in a helper column
    Hi Pete. They pretty much asked to keep it in one column. By using a helper, I would still need to return the Event ID to the Session and using a formula. This is why I am looking for a VBA solution.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Creating a macro to replace a formula that takes forever to calculate

    There's a performance penalty for doing things in VBA. If performance is important, I would suggest you do all you can to do it without VBA. A few things I notice:

    1) Your function is concatenating column H and column V inside of the function. This means that every copy of the function must repeat this concatenation 50k concatenations times however many copies of this function you need is a significant duplication of effort. I think the first thing I would do would be to add a helper column that performs the concatenation once and save all of that duplicated effort. I know that we despise helper columns (well some of you do, I know some of the more experienced users on here are rather fond of helper columns), but I have seen examples on this forum of a spreadsheet going from "so slow as to be nearly unusable" to computing nearly instantaneously by simply adding a few helper columns to eliminate duplicated effort.
    2) Your MATCH() function is using a slow, inefficient, linear lookup (3rd argument=0). Nothing slows a spreadsheet down like an inefficient linear lookup. After creating the helper column in 1, sort the list using that helper column.

    I would expect that those two steps should improve the performance of your spreadsheet.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Creating a macro to replace a formula that takes forever to calculate

    think the first thing I would do would be to add a helper column that performs the concatenation once and save all of that duplicated effort
    I figured out that if I use a helper would save me, but I cannot use one due to different work related reasons

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Creating a macro to replace a formula that takes forever to calculate

    Ah got you. Try this code then.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Creating a macro to replace a formula that takes forever to calculate

    CK76, you sir are amazing. I've searched and tried different ways to do it, but I failed every time. This is a evidence of the necesity to learn new thing. Thank you a lot!

  9. #9
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Creating a macro to replace a formula that takes forever to calculate

    You are welcome and thanks for the rep

+ 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. [SOLVED] InStr macro takes forever.
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-06-2017, 10:40 AM
  2. Macro takes forever after upgrading from excel 20007 to 2010
    By Yigal in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-05-2014, 10:45 AM
  3. Macro Takes forever To Execute
    By daveyc18 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2014, 11:14 AM
  4. Replies: 8
    Last Post: 04-15-2014, 04:35 AM
  5. Copying column w/ VBA takes forever
    By patatvs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2010, 01:42 PM
  6. Replies: 7
    Last Post: 12-19-2008, 10:57 PM
  7. hiding a few rows with a macro takes forever
    By Conor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2007, 06:34 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