+ Reply to Thread
Results 1 to 5 of 5

Create Sparklines very slow when lots of Sparkline Groups already existed for given launch

  1. #1
    Registered User
    Join Date
    06-17-2014
    Location
    OK
    MS-Off Ver
    2013
    Posts
    4

    Create Sparklines very slow when lots of Sparkline Groups already existed for given launch

    Hello,

    I have an Excel file that I use for some personal projects for which I could really please use some help. The macro will create or delete non-contiguous sparklines; only one worksheet would ever have Sparklines and no other charts are present in the workbook. The data for the sparklines is kept on a different sheet then the sparklines. The quantity of sparklines will vary depending on source data and can be upwards of 10,000+.

    If the xlsb file is launched when no sparklines are exist, then the code to create the sparklines runs upwards of 10 to 30 times faster than if the sparklines had previously existed for a given launch of the file. Removing the sparklines or deleting and recreating the entire Target sheet does not improve the speed, only saving without Sparklines and relaunching.

    The slow performance can have a major impact. For example: ~8,000 Sparklines takes ~55 seconds to execute when running quickly but can take ~1700 seconds if Sparklines were either already present when the file was launched or had previously been created and then removed. Smaller sets of Sparklines would naturally take less time to create but would still suffer from the same difference in the speed at which they are created, i.e. a smaller set of Sparklines might take 1.5 and 20 seconds to execute for the fast and slow executions respectively.

    Sparklines are placed into cells that previously contained numerical results, and the results are Backuped up on a different worksheet as they would be replaced when Sparklines are removed. There are no formulas or conditional formatting in the workbook.

    ToggleSparklines function is triggered from the Target sheet via a button so the Target sheet is active at the time the function is triggered.

    I have spent hrs and hrs trying to figure out this problem, and I have exhausted everything I can think to try. This is my first time submitting a thread so hopefully I am doing it correctly.

    I would really appreciate any possible suggestions. Thank you very much

    NOTE: the sample code has been removed since the code contained in subsequent posts is targeted more at the specific issue.
    Last edited by Misaak; 07-06-2018 at 07:48 AM. Reason: Changes were made to remove unnecessary sample code and refine the thread title once the true nature of the difficulty was understood so that people reviewing the information would not be bogged down

  2. #2
    Registered User
    Join Date
    06-17-2014
    Location
    OK
    MS-Off Ver
    2013
    Posts
    4

    Re: Sparkline macro runs slower when Sparklines already present for given launch

    UPDATE: I have determined that the change in performance is due in some way to the removal of the previous Sparklines. If I switch between Numerical results and Sparklines without ever officially removing the previous Sparklines, then the performance is always just as fast. I have attempted to remove Sparklines using the below two methods, and both cause the performance problem for subsequent Sparkline creations.

    Is there a better way to remove numerous Sparklines from a worksheet? Thank you

    Method 1:
    On Error Resume Next
    For Each SLGrp In DataRng.SparklineGroups
    SLGrp.Delete
    Next SLGrp
    On Error GoTo 0
    Method 2:
    DataRng.SparklineGroups.Clear

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Sparkline macro runs slower when Sparklines already present for given launch

    Does DataRng.Clear perform any better?

  4. #4
    Registered User
    Join Date
    06-17-2014
    Location
    OK
    MS-Off Ver
    2013
    Posts
    4

    Re: Sparkline macro runs slower when Sparklines already present for given launch

    UPDATE: I have created a sample file that illustrates the difficulty through the simple act of creating and removing Sparklines via the Toggle Sparklines button.

    If the file is saved and closed without any Sparklines present, then creating Sparklines the next time the file is launched would only take ~2 seconds. However, if the Sparklines are then removed and recreated via the Toggle Button, the creation would then take ~24 seconds.

    If the file is saved and closed with Sparklines present, then the next time the Sparklines are created after having removed the previous Sparklines would take ~24 seconds.

    The performance hit is generally the same regardless of whether or not the Sparklines are removed via Rng.SparklineGroups.Clear or SLGrp.Delete.

    The sample is relatively small so the overall impact is minimal although still 12x longer, but the overall duration can increase rapidly when the number of Sparklines increases, easily upwards of 30 minutes or longer.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-17-2014
    Location
    OK
    MS-Off Ver
    2013
    Posts
    4

    Re: Sparkline macro runs slower when Sparklines already present for given launch

    WORK AROUND SOLUTION:
    After many, many hours, I have finally stumbled upon what appears to be a viable work around for the difficulty although I still think the culprit must be some bug in MS Excel.

    The solution was to add each non-contiguous Sparkline as it was created to a consolidated single Sparkline Group.

    The previous method would result in one Sparkline Group for each Sparkline so there would be thousands of Sparkline Groups which would then experience the performance hit if the Sparklines/Sparkline Groups were removed and re-created on the same launch of the fi

    The current method used to add each non-contiguous Sparkline to a consolidated Group is to "Select" the full range in the destination worksheet that would receive the Sparklines and then perform the Sparkline Group command. There might be a better method of creating and adding non-contiguous Sparklines to a group that doesn't rely on a worksheet "Select" command, but I haven't yet figured out how to do it for Sparklines that exist in different rows and columns. Also, the addition of the Sparklines to a group has to be done as each Sparkline is created rather than after all of the Sparklines have been created otherwise the performance difficulty is not improved.

    The below code is a sample set that switches between adding and removing Sparklines. As it stands, my sample set now consistently takes less than 2 seconds to create the Sparklines, regardless of whether or not Sparklines had previously existed or not.

    NOTE: during the testing, I also identified that the performance difficulty didn't start occurring on my system until somewhere between 650-800 Sparklines/Sparkline Groups had been created and removed.

    Please Login or Register  to view this content.
    Last edited by Misaak; 07-06-2018 at 08:00 AM. Reason: Refine the description of the work around solution

+ 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. Macro in Excel 2016 runs MUCH slower when ANOTHER spreadsheet is open?
    By Ed_Collins in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-17-2017, 06:59 PM
  2. [SOLVED] Sparklines - Creating Summary and want to source sparkline data from another table
    By AdamParker in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 09-08-2016, 08:49 AM
  3. [SOLVED] Macro running slower and slower
    By jj4jj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2016, 10:26 AM
  4. Excel macro getting slower and slower.
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-24-2011, 06:41 AM
  5. macro runs much slower in excel 2007
    By hputhraya in forum Excel General
    Replies: 2
    Last Post: 03-25-2010, 03:54 AM
  6. [SOLVED] Embedded Excel macro runs 100X slower
    By JS in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-24-2006, 07:20 PM
  7. String manipulation in macro runs slower each time ran.
    By Lamination Technology in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-16-2006, 02:00 AM

Tags for this Thread

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