+ Reply to Thread
Results 1 to 5 of 5

Slow macro, slow pc or wrong code?

  1. #1
    Registered User
    Join Date
    03-08-2016
    Location
    London
    MS-Off Ver
    2007
    Posts
    4

    Slow macro, slow pc or wrong code?

    Hi, i have created a macro to change some values into a cell. i have a dataset with many rows and i would like to divide those rows in packs. my macro asks the pack size, the first and the last row where i want to calculate the pack and then with a loop it will update the value of the "Pack column".


    more or less this is the code i used:
    Please Login or Register  to view this content.
    ColLetter contains the column letter (like "B") where i want to put my pack number.

    if i choose a size of 2000 (PackSize=2000) it will put Firstpack for the first 2000 rows after firstrow and then FirstPack+1 for the next 2000 and so on.


    I don't understand why it's so slow, say that i have about 10.000 rows is it normal that the macro takes up to 5 minutes to finish the loop? i've created others but i felt this is very slow, any suggestion?

    thanks

    Massimo

  2. #2
    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,911

    Re: Slow macro, slow pc or wrong code?

    Writing to one cell at a time is always slow. Either populate an array with the values and then assign that to the whole range, or even just assign in batches of Packsize number of cells, since you're putting the same value in each block.
    Rory

  3. #3
    Registered User
    Join Date
    03-08-2016
    Location
    London
    MS-Off Ver
    2007
    Posts
    4

    Re: Slow macro, slow pc or wrong code?

    ok thanks, I'll try one of those as soon as i understand how to do it xD

    thanks

  4. #4
    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,911

    Re: Slow macro, slow pc or wrong code?

    The latter option should be a small change like this:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-08-2016
    Location
    London
    MS-Off Ver
    2007
    Posts
    4

    Re: Slow macro, slow pc or wrong code?

    Thanks rorya, it is much faster but it creates more values than needed, i.e. if i have 3500 numbers and i choose a pack size of 2000 it will numerate 4000 and i have 500 extra rows with a pack number... maybe i should use an array?

    EDIT
    I was thinking i might add an if and resize the packsize, something like that;

    Please Login or Register  to view this content.
    it seems to be working...

    thanks a lot!!!
    Last edited by corky81; 09-24-2018 at 07:18 AM.

+ 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 hides the wrong rows and is too slow
    By Marvelous in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-30-2014, 05:01 PM
  2. Macro is running real slow and makes navigating the worksheet really slow after execution.
    By MichWolverines in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2013, 04:29 PM
  3. [SOLVED] slow computer (slow clipboard) breaks my macro
    By twilsonco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 09:16 PM
  4. Macro/VBA Code Assistance - very slow on text
    By n3mcx1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2012, 08:53 AM
  5. Macro code is running to slow
    By chsaav in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2011, 05:00 AM
  6. I have Vlookup and autofill macro, its slow, what Im doing wrong?
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-06-2011, 10:18 PM
  7. Slow Macro ? - Need Assistance in Optimizing Code
    By robby10 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-12-2010, 11:43 AM

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