+ Reply to Thread
Results 1 to 11 of 11

Amend code to run faster

  1. #1
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327

    Amend code to run faster

    I have the following code kindly supplied to me by someone else and I'd like to know if anyone can suggest any ways to speed up the running of it. It currently takes about 4 minutes to run (there are about 5000 cells to loop through)

    Basically it looks for a value in Col C - works out the number of rows to fill up by searching a range in Col D - then copies value in Col C up by that number of rows.

    Please Login or Register  to view this content.
    Any help would be appreciated

    Regards

    Seamus

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    What value is it looking for?
    Why are you looping through all the cells?
    Can you give a more detailed explanation of what you want to do, maybe attach an example workbook
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Sure can, roy. Sample book attached.

    Column C contains reason for activity (sickness, maternity leave etc). Column D contains the staff who worked those shifts.

    Currently the reason for activity is only in the subtotal cell of col C and I need to "fill up" those reasons by the number of cells in Col D.

    I'd be grateful if you's take a look at the book and advise me on the best way forward.

    Regards

    Seamus
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    See if this is any faster
    Please Login or Register  to view this content.
    Last edited by royUK; 09-05-2008 at 04:35 AM.

  5. #5
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Sorry roy. But that appears to change the values in Col D. Will keep looking at it though and try to figure out something.

    Thanks

    Seamus

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It changes the values in column C -
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Many many thanks roy,

    With just a slight adjustment in the code it now woeks like a charm

    Please Login or Register  to view this content.
    Regards

    Seamus

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Why did you need to change the way that rng is set? I see a typo, 6 should be 4 but that's all.

  9. #9
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    roy,

    I Debug.Printed using your original code and it moved as follows, D2, E2, F2, D3, E3, F3 etc - I realise now that was because of the typo 6 instead of 4 - but I am now using your amended code.

    Thanks

    Seamus

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    No problem, glad it helped.

    Out of interest is it faster than the oriinal code?

  11. #11
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Absolutely - this code just flies through in a matter of seconds while the old code looping through took between 4 and 5 minutes.

    Good work

    Seamus

+ 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. Copying from one workbook and pasting into another additon to code
    By snordr17 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2008, 05:39 PM
  2. Activate different workbook
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 05-02-2008, 12:43 PM
  3. Excel closes when using VBA to write VBA code
    By btoback in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2007, 03:42 PM
  4. Adding code to a form on the fly...
    By Ara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2007, 03:47 PM
  5. Help making code run faster
    By dignityy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2006, 11:42 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