+ Reply to Thread
Results 1 to 8 of 8

Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Please Login or Register  to view this content.
    Last edited by Fotis1991; 10-07-2013 at 08:08 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    please don't use range names, I can not understand what you are doing.
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Please see code without range names below.

    Please Login or Register  to view this content.
    Last edited by Fotis1991; 10-07-2013 at 08:08 AM.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Hi

    Just looking at your code line by line.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 10-06-2013 at 12:15 PM.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Hi, John Vieren,

    like stated it´s the mere number of loops that can hardly be manipulated or optimized. Since yoiu turned off calculation you need to recalculate on each loop, and as it is set from your thread title you want to add the numbers to thes existing numbers in the other range.

    I set a sample sheet holding teh loop number in A1, simple formulas like
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    for some cells in the range to calculate (but I kept my Excel on aitomatuce calculation). What I moved was the copying of formats - I think it´s good enough to do it once after the round of loops is done. Fiurthermore I split the macro up in slices (here of 8 rounds a 2500 loops). Each turn on my PC will take between 50 and 60 seconds, the toal püackage runs for about 8 minutes (not really something that I like: my Excel being blocked that long).

    Code I used:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Thank you for your response, please see further commentary below.

    MEHMETCIK Why bother with this line? In line 7 you are overwriting this whole selection

    JOHN VIEREN Because each time i run the macro, i need to clear the data from the prior macro run.

    MEHMETCIK Why is this line within your loop? it will be actioned 20, 000 times.

    JOHN VIEREN I am reading in 20,000 data records and each record is used to make certain calculations and the output for each record is sumed (i.e calculations for 20,000 are added togeter)

    MEHMETCIK This sub is run 20, 000 times so is it efficient ?

    JOHN VIEREN No not eficient it runs slow hence my question.

    MEHMETCIK The next three lines can be replaced by a single line. The formating should be done outside the loop if required.

    JOHN VIEREN Yes I agree this can be improved, thank you.

    MEHMETCIK 'Replace your three lines

    JOHN VIEREN This will not add up the results for the 20,000 records will it?
    Last edited by John Vieren; 10-10-2013 at 05:53 AM.

  7. #7
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Hong Kong
    MS-Off Ver
    Office 365 PC Version
    Posts
    204

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Dear Holger,

    Thanks for your response.

    I am not an expert with VBA and dont fully understand your code.

    In any case, why would splitting it up into 8 rounds make it run any faster?

    And yes I agree the formating can be done at the end and this has made the macro run faster.

    Kindest regards JV

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Slow VBA Code for simple Loop and add pasted values Any Way to Speed Up

    Hi, John Vieren,

    it doesn´t run faster but you feel like that as you do have a smaller amount of time to wait until Excel is free again for other work.

    Ciao,
    Holger

+ 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. How to speed up loop code
    By notreallyIT in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2013, 06:07 PM
  2. Speed Up VBA Loop Code
    By rlsublime in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 12-30-2012, 07:20 PM
  3. [SOLVED] Speed up slow macro loop
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-15-2012, 11:41 AM
  4. [SOLVED] Slow VBA Loop Code
    By krcaldwell31 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2012, 09:14 AM
  5. loop vs. simple function, huge difference in speed, why?
    By losmi8 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2010, 04:33 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